Documentation
¶
Overview ¶
Package subagent implements a Tool that delegates work to specialized sub-agents with isolated contexts. Four execution modes are supported: single, parallel, chain, and background.
Index ¶
- type Config
- type Tool
- func (t *Tool) Description() string
- func (t *Tool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)
- func (t *Tool) Label() string
- func (t *Tool) Name() string
- func (t *Tool) Schema() map[string]any
- func (t *Tool) SetBgOutputFactory(fn func(taskID, agentName string) (io.WriteCloser, string, error))
- func (t *Tool) SetCreateModel(fn func(name string) (agentcore.ChatModel, error))
- func (t *Tool) SetNotifyFn(fn func(agentcore.AgentMessage))
- func (t *Tool) SetTaskRuntime(rt *task.Runtime)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Name string
Description string
// Model is resolved when each sub-agent run starts. Wrappers that swap the
// underlying model at runtime (e.g. agentcore.SwappableModel) take effect
// on the next sub-agent run.
Model agentcore.ChatModel
SystemPrompt string
Tools []agentcore.Tool
MaxTurns int
// MaxRetries caps the LLM call retry count for retryable errors within
// this sub-agent's loop. 0 (default) disables retry entirely.
MaxRetries int
// ToolsAreIdempotent declares this sub-agent's tools are safe to
// re-execute. See agentcore.WithToolsAreIdempotent for full rationale.
ToolsAreIdempotent bool
// StopAfterTools lists tool names that trigger early loop exit after
// successful execution.
StopAfterTools []string
// StopAfterToolResult is the result-aware variant of StopAfterTools.
StopAfterToolResult func(toolName string, result json.RawMessage) bool
// OnMessage, if non-nil, is called after each message is appended to
// context. The agentName and task are provided for session routing.
OnMessage func(agentName, task string, msg agentcore.AgentMessage)
// Optional context lifecycle hooks for long-running sub-agents.
ContextManager agentcore.ContextManager
ContextManagerFactory func(model agentcore.ChatModel) agentcore.ContextManager
ConvertToLLM func(msgs []agentcore.AgentMessage) []agentcore.Message
// StopGuardFactory, if non-nil, creates a fresh StopGuard for each run.
StopGuardFactory func(agentName, task string) agentcore.StopGuard
}
Config defines a sub-agent's identity and capabilities.
type Tool ¶
type Tool struct {
// contains filtered or unexported fields
}
Tool implements agentcore.Tool. The main agent calls this tool to delegate tasks to specialized sub-agents with isolated contexts.
func (*Tool) Description ¶
func (*Tool) Execute ¶
func (t *Tool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)
func (*Tool) SetBgOutputFactory ¶
func (t *Tool) SetBgOutputFactory(fn func(taskID, agentName string) (io.WriteCloser, string, error))
SetBgOutputFactory sets the factory that creates output writers for background tasks. The factory receives the task ID and agent name and returns a writer, file path, and error.
func (*Tool) SetCreateModel ¶
SetCreateModel sets the factory for resolving model names to ChatModel instances at runtime. Enables LLM to override the default model per call.
func (*Tool) SetNotifyFn ¶
func (t *Tool) SetNotifyFn(fn func(agentcore.AgentMessage))
SetNotifyFn sets the callback invoked when a background task completes. Typically bound to Agent.FollowUp so the main agent receives the result as a follow-up message.
func (*Tool) SetTaskRuntime ¶
SetTaskRuntime sets the shared task runtime for background task registration. Required for background mode.