MCPcopy Create free account
hub / github.com/astercloud/aster / Run

Method Run

server/handlers/agent.go:320–400  ·  view source on GitHub ↗

Run runs an agent with a message

(c *gin.Context)

Source from the content-addressed store, hash-verified

318
319// Run runs an agent with a message
320func (h *AgentHandler) Run(c *gin.Context) {
321 ctx := c.Request.Context()
322 id := c.Param("id")
323
324 var req struct {
325 Message string `json:"message" binding:"required"`
326 Context map[string]any `json:"context"`
327 }
328
329 if err := c.ShouldBindJSON(&req); err != nil {
330 c.JSON(http.StatusBadRequest, gin.H{
331 "success": false,
332 "error": gin.H{
333 "code": "bad_request",
334 "message": err.Error(),
335 },
336 })
337 return
338 }
339
340 // Get agent record
341 var agentRecord AgentRecord
342 if err := (*h.store).Get(ctx, "agents", id, &agentRecord); err != nil {
343 if errors.Is(err, store.ErrNotFound) {
344 c.JSON(http.StatusNotFound, gin.H{
345 "success": false,
346 "error": gin.H{
347 "code": "not_found",
348 "message": "Agent not found",
349 },
350 })
351 return
352 }
353 c.JSON(http.StatusInternalServerError, gin.H{
354 "success": false,
355 "error": gin.H{
356 "code": "internal_error",
357 "message": "Failed to get agent: " + err.Error(),
358 },
359 })
360 return
361 }
362
363 // Create agent instance
364 ag, err := agent.Create(ctx, agentRecord.Config, h.deps)
365 if err != nil {
366 c.JSON(http.StatusInternalServerError, gin.H{
367 "success": false,
368 "error": gin.H{
369 "code": "internal_error",
370 "message": "Failed to create agent: " + err.Error(),
371 },
372 })
373 return
374 }
375 defer func() { _ = ag.Close() }()
376
377 // Send message

Callers 15

TestToolHandlersFunction · 0.45
TestMiddlewareHandlersFunction · 0.45
TestTelemetryHandlersFunction · 0.45
TestSystemHandlersFunction · 0.45
TestMCPHandlersFunction · 0.45
TestEvalHandlersFunction · 0.45
TestValidationErrorsFunction · 0.45
TestQueryParametersFunction · 0.45
TestResponseFormatFunction · 0.45
TestAgentLifecycleFunction · 0.45
TestPoolOperationsFunction · 0.45

Calls 8

CreateFunction · 0.92
InfoFunction · 0.92
JSONMethod · 0.80
ContextMethod · 0.65
ErrorMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.65
SendMethod · 0.45

Tested by 15

TestToolHandlersFunction · 0.36
TestMiddlewareHandlersFunction · 0.36
TestTelemetryHandlersFunction · 0.36
TestSystemHandlersFunction · 0.36
TestMCPHandlersFunction · 0.36
TestEvalHandlersFunction · 0.36
TestValidationErrorsFunction · 0.36
TestQueryParametersFunction · 0.36
TestResponseFormatFunction · 0.36
TestAgentLifecycleFunction · 0.36
TestPoolOperationsFunction · 0.36