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

Method buildAgentConfig

pkg/agent/subagent.go:488–532  ·  view source on GitHub ↗

buildAgentConfig 构建子 Agent 配置

(spec *types.SubAgentSpec, req *types.SubAgentRequest, taskID string)

Source from the content-addressed store, hash-verified

486
487// buildAgentConfig 构建子 Agent 配置
488func (m *SubAgentManager) buildAgentConfig(spec *types.SubAgentSpec, req *types.SubAgentRequest, taskID string) *types.AgentConfig {
489 // 创建子 Agent 专用模板 ID
490 templateID := fmt.Sprintf("subagent-%s-%s", spec.Name, taskID[:8])
491
492 // 注册临时模板
493 template := &types.AgentTemplateDefinition{
494 ID: templateID,
495 SystemPrompt: spec.Prompt,
496 Model: spec.Model,
497 Tools: spec.Tools,
498 Runtime: &types.AgentTemplateRuntime{
499 ExposeThinking: false,
500 Todo: &types.TodoConfig{
501 Enabled: false,
502 },
503 },
504 }
505 m.deps.TemplateRegistry.Register(template)
506
507 // 构建元数据
508 metadata := make(map[string]any)
509 if req.Context != nil {
510 maps.Copy(metadata, req.Context)
511 }
512 metadata["subagent_task_id"] = taskID
513 metadata["subagent_type"] = spec.Name
514 metadata["parent_agent_id"] = req.ParentAgentID
515
516 config := &types.AgentConfig{
517 AgentID: "subagent-" + taskID[:8],
518 TemplateID: templateID,
519 Metadata: metadata,
520 }
521
522 // 如果指定了模型,设置 ModelConfig
523 if spec.Model != "" {
524 inferredProvider := inferProviderFromModel(spec.Model)
525 config.ModelConfig = &types.ModelConfig{
526 Provider: inferredProvider,
527 Model: spec.Model,
528 }
529 }
530
531 return config
532}
533
534// buildTaskMessage 构建任务消息
535func (m *SubAgentManager) buildTaskMessage(req *types.SubAgentRequest, spec *types.SubAgentSpec) string {

Callers 2

ExecuteMethod · 0.95
ExecuteAsyncMethod · 0.95

Calls 3

inferProviderFromModelFunction · 0.85
CopyMethod · 0.80
RegisterMethod · 0.65

Tested by

no test coverage detected