CreateAgent creates a new agent in the pool
(c *gin.Context)
| 35 | |
| 36 | // CreateAgent creates a new agent in the pool |
| 37 | func (h *PoolHandler) CreateAgent(c *gin.Context) { |
| 38 | var req struct { |
| 39 | AgentID string `json:"agent_id"` |
| 40 | TemplateID string `json:"template_id" binding:"required"` |
| 41 | ModelConfig *types.ModelConfig `json:"model_config"` |
| 42 | Sandbox *types.SandboxConfig `json:"sandbox"` |
| 43 | Middlewares []string `json:"middlewares"` |
| 44 | MiddlewareCfg map[string]map[string]any `json:"middleware_config"` |
| 45 | Metadata map[string]any `json:"metadata"` |
| 46 | } |
| 47 | |
| 48 | if err := c.ShouldBindJSON(&req); err != nil { |
| 49 | c.JSON(http.StatusBadRequest, gin.H{ |
| 50 | "success": false, |
| 51 | "error": gin.H{ |
| 52 | "code": "bad_request", |
| 53 | "message": err.Error(), |
| 54 | }, |
| 55 | }) |
| 56 | return |
| 57 | } |
| 58 | |
| 59 | ctx := c.Request.Context() |
| 60 | |
| 61 | // Create agent config |
| 62 | config := &types.AgentConfig{ |
| 63 | AgentID: req.AgentID, |
| 64 | TemplateID: req.TemplateID, |
| 65 | ModelConfig: req.ModelConfig, |
| 66 | Sandbox: req.Sandbox, |
| 67 | Middlewares: req.Middlewares, |
| 68 | MiddlewareConfig: req.MiddlewareCfg, |
| 69 | Metadata: req.Metadata, |
| 70 | } |
| 71 | |
| 72 | // Create agent in pool |
| 73 | ag, err := h.pool.Create(ctx, config) |
| 74 | if err != nil { |
| 75 | logging.Error(ctx, "pool.create.error", map[string]any{ |
| 76 | "error": err.Error(), |
| 77 | }) |
| 78 | c.JSON(http.StatusInternalServerError, gin.H{ |
| 79 | "success": false, |
| 80 | "error": gin.H{ |
| 81 | "code": "internal_error", |
| 82 | "message": "Failed to create agent: " + err.Error(), |
| 83 | }, |
| 84 | }) |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | logging.Info(ctx, "pool.agent.created", map[string]any{ |
| 89 | "agent_id": ag.ID(), |
| 90 | }) |
| 91 | |
| 92 | c.JSON(http.StatusCreated, gin.H{ |
| 93 | "success": true, |
| 94 | "data": gin.H{ |