Documentation
¶
Overview ¶
Package agent provides an AI assistant framework with tool execution, memory, and session persistence.
The agent package allows you to create conversational AI assistants that can:
- Chat with users using any LLM provider
- Execute tools automatically during conversations
- Maintain long-term memory about users across sessions
- Persist conversation history with pluggable session stores
Basic Usage ¶
llmClient, _ := providers.NewLLM(model.ProviderOpenAI,
providers.WithAPIKey(os.Getenv("OPENAI_API_KEY")),
providers.WithModel(model.OpenAIModels[model.GPT4oMini]),
)
myAgent := agent.New(llmClient,
agent.WithSystemPrompt("You are a helpful assistant."),
)
response, _ := myAgent.Chat(ctx, "Hello!")
fmt.Println(response.Content)
With Tools ¶
Agents can use tools to perform actions:
myAgent := agent.New(llmClient,
agent.WithSystemPrompt("You are a weather assistant."),
agent.WithTools(&WeatherTool{}),
)
With Session Persistence ¶
Conversation history can be persisted using session stores:
myAgent := agent.New(llmClient,
agent.WithSystemPrompt("You are a helpful assistant."),
agent.WithSession("user-123", session.FileStore("./sessions")),
)
With Memory ¶
Long-term memory allows the agent to remember facts about users:
myAgent := agent.New(llmClient,
agent.WithSystemPrompt("You are a personal assistant."),
agent.WithMemory("user-123", memoryStore,
memory.AutoExtract(),
memory.AutoDedup(),
),
)
Streaming Responses ¶
For real-time responses, use ChatStream:
for event := range myAgent.ChatStream(ctx, "Tell me a story") {
switch event.Type {
case types.EventContentDelta:
fmt.Print(event.Content)
case types.EventError:
log.Fatal(event.Error)
}
}
Index ¶
- func ParseToolInput[T any](input string) (T, error)
- type Agent
- func (a *Agent) BuildContextMessages(ctx context.Context, userMessage string) ([]message.Message, error)
- func (a *Agent) Chat(ctx context.Context, userMessage string, opts ...ChatOption) (*ChatResponse, error)
- func (a *Agent) ChatStream(ctx context.Context, userMessage string, opts ...ChatOption) <-chan ChatEvent
- func (a *Agent) Continue(ctx context.Context, toolResults []message.ToolResult, opts ...ChatOption) (*ChatResponse, error)
- func (a *Agent) ContinueStream(ctx context.Context, toolResults []message.ToolResult, opts ...ChatOption) <-chan ChatEvent
- func (a *Agent) PeekContextMessages(ctx context.Context, userMessage string) ([]message.Message, error)
- type BackgroundTask
- type ChatEvent
- type ChatOption
- type ChatResponse
- type ConfirmationProvider
- type FanOutConfig
- type HandoffConfig
- type HookAction
- type HookEvent
- type HookEventType
- type Hooks
- type InstructionProvider
- type LifecycleContext
- type LifecycleResult
- type ModelCallContext
- type ModelCallResult
- type ModelErrorContext
- type ModelErrorResult
- type ModelResponseContext
- type ModelResponseResult
- type Option
- func WithAutoExecute(auto bool) Option
- func WithConfirmationProvider(provider ConfirmationProvider) Option
- func WithContextStrategy(strategy tokens.Strategy, maxContextTokens int64) Option
- func WithCoordinatorMode() Option
- func WithFanOut(configs ...FanOutConfig) Option
- func WithHandoffs(configs ...HandoffConfig) Option
- func WithHooks(hooks ...Hooks) Option
- func WithInstructionProvider(provider InstructionProvider) Option
- func WithMailbox(mb team.Mailbox) Option
- func WithMaxIterations(maxIter int) Option
- func WithMaxParallelTools(maxTools int) Option
- func WithMemory(id string, store memory.Store, opts ...memory.Option) Option
- func WithSequentialToolExecution() Option
- func WithSession(id string, store session.Store) Option
- func WithState(state map[string]any) Option
- func WithSubAgents(configs ...SubAgentConfig) Option
- func WithSystemPrompt(prompt string) Option
- func WithTeam(config team.Config) Option
- func WithTeammateTemplates(templates map[string]*Agent) Option
- func WithTools(tools ...tool.BaseTool) Option
- func WithToolsets(toolsets ...tool.Toolset) Option
- type PostToolUseContext
- type PostToolUseResult
- type PreToolUseResult
- type RunContext
- type SubAgentConfig
- type SubagentEventContext
- type TaskManager
- func (tm *TaskManager) CancelAll()
- func (tm *TaskManager) GetResult(ctx context.Context, taskID string, wait bool, timeout time.Duration) (*BackgroundTask, error)
- func (tm *TaskManager) Launch(ctx context.Context, agentName string, a *Agent, task string, ...) string
- func (tm *TaskManager) ListAll() []*BackgroundTask
- func (tm *TaskManager) Stop(taskID string) error
- func (tm *TaskManager) WaitAll()
- type TaskStatus
- type TeamMessageContext
- type TeammateEventContext
- type ToolErrorContext
- type ToolErrorResult
- type ToolExecutionResult
- type ToolUseContext
- type UserMessageContext
- type UserMessageResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseToolInput ¶
ParseToolInput parses a JSON tool input string into the specified type. This is a helper function for implementing tool.BaseTool.Run().
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is an AI assistant that can chat with users, use tools, and maintain memory. Create one using New() with functional options.
func New ¶
New creates a new Agent with the given LLM client and options. The agent can be configured with tools, memory, session persistence, and more.
Example:
agent := agent.New(llmClient,
agent.WithSystemPrompt("You are a helpful assistant."),
agent.WithTools(&myTool{}),
agent.WithSession("conv-1", session.FileStore("./sessions")),
agent.WithMemory("user-123", myMemoryStore, memory.AutoExtract()),
)
func (*Agent) BuildContextMessages ¶
func (a *Agent) BuildContextMessages( ctx context.Context, userMessage string, ) ([]message.Message, error)
BuildContextMessages returns the messages that would be sent to the LLM after applying the context strategy. This is useful for debugging and testing context management. WARNING: This method modifies the session by adding the user message.
func (*Agent) Chat ¶
func (a *Agent) Chat( ctx context.Context, userMessage string, opts ...ChatOption, ) (*ChatResponse, error)
Chat sends a message to the agent and returns the response. If the agent has tools configured, it will automatically execute them. If memory is configured, relevant memories are injected into the context. If a session is configured, the conversation history is persisted. If handoffs are configured, the active agent may change mid-conversation.
func (*Agent) ChatStream ¶
func (a *Agent) ChatStream( ctx context.Context, userMessage string, opts ...ChatOption, ) <-chan ChatEvent
ChatStream sends a message to the agent and returns a channel of streaming events. Events include content deltas, tool calls, handoff notifications, and the final response. The channel is closed when the response is complete or an error occurs.
func (*Agent) Continue ¶
func (a *Agent) Continue( ctx context.Context, toolResults []message.ToolResult, opts ...ChatOption, ) (*ChatResponse, error)
Continue resumes the agent loop with externally-executed tool results. Use this after a Chat() call returned pending ToolCalls (e.g. with autoExecute disabled or after hitting the max iteration limit). Requires a session to be configured.
func (*Agent) ContinueStream ¶
func (a *Agent) ContinueStream( ctx context.Context, toolResults []message.ToolResult, opts ...ChatOption, ) <-chan ChatEvent
ContinueStream is the streaming variant of Continue. It resumes the agent loop with externally-executed tool results and returns a channel of streaming events.
type BackgroundTask ¶
type BackgroundTask struct {
ID string
AgentName string
Status TaskStatus
Result string
Error string
StartedAt time.Time
EndedAt time.Time
// contains filtered or unexported fields
}
BackgroundTask holds the state and result of an asynchronous sub-agent execution.
type ChatEvent ¶
type ChatEvent struct {
// Type identifies the kind of event (content_delta, tool_use_start, complete, error, etc.).
Type types.EventType
// Content contains partial text for EventContentDelta events.
Content string
// Thinking contains chain-of-thought text for EventThinkingDelta events.
Thinking string
// ToolCall contains tool call information for tool use events.
ToolCall *message.ToolCall
// ToolResult contains the result of a tool execution.
ToolResult *ToolExecutionResult
// Response contains the final ChatResponse for EventComplete events.
Response *ChatResponse
// Error contains error details for EventError events.
Error error
// AgentName is set on EventHandoff events to indicate the target agent.
AgentName string
// ConfirmationRequest is set on EventConfirmationRequired events with the details of the pending request.
ConfirmationRequest *tool.ConfirmationRequest
// TeamMessage is set on EventTeamMessage events with the message details.
TeamMessage *team.Message
}
ChatEvent represents a single streaming event emitted during ChatStream.
type ChatOption ¶
type ChatOption func(*chatConfig)
ChatOption is a functional option for per-call overrides on Chat() and ChatStream().
func WithMaxTurns ¶
func WithMaxTurns(n int) ChatOption
WithMaxTurns sets the maximum number of tool-execution iterations for this call. Overrides the agent's WithMaxIterations setting. 0 means use the agent default.
type ChatResponse ¶
type ChatResponse struct {
// Content is the final text response from the agent.
Content string
// ToolCalls contains any pending tool calls from the final LLM response.
ToolCalls []message.ToolCall
// ToolResults contains the results of all tool executions during the conversation.
ToolResults []ToolExecutionResult
// Usage is the aggregated token usage across all LLM calls in the agent loop.
Usage llm.TokenUsage
// FinishReason indicates why the agent stopped (end_turn, max_tokens, tool_use, etc.).
FinishReason message.FinishReason
// AgentName is the name of the agent that produced this response, set when a handoff occurred.
AgentName string
// TotalToolCalls is the total number of tool invocations across all iterations.
TotalToolCalls int
// TotalDuration is the wall-clock time from Chat() entry to return.
TotalDuration time.Duration
// TotalTurns is the number of LLM round-trips (API calls) made during the conversation.
TotalTurns int
}
ChatResponse represents the complete result of an agent Chat or ChatStream call. Usage is aggregated across all LLM round-trips in the agent loop, not just the final call.
type ConfirmationProvider ¶
ConfirmationProvider is a callback that decides whether a tool call should proceed. It blocks until the consumer provides a decision. Return true to approve, false to reject. The provider is called both for tools with RequireConfirmation=true on their Info and for tools that call tool.RequestConfirmation() from within Run().
type FanOutConfig ¶
type FanOutConfig struct {
// Name is the tool name the parent agent uses to invoke this fan-out.
Name string
// Description is the tool description shown to the LLM.
Description string
// Agent is the agent instance that handles each individual task.
Agent *Agent
// MaxConcurrency limits parallel task execution. 0 means unlimited.
MaxConcurrency int
}
FanOutConfig configures a fan-out tool that distributes multiple tasks to parallel instances of the same agent. The parent agent invokes this tool with a list of tasks, and each task is sent to a separate Chat() call concurrently.
type HandoffConfig ¶
type HandoffConfig struct {
// Name identifies the target agent. The generated tool name is "transfer_to_<Name>".
Name string
// Description explains when this handoff should be used, shown to the LLM.
Description string
// Agent is the target agent that receives control after the handoff.
Agent *Agent
}
HandoffConfig configures a handoff target that the current agent can transfer control to. When a handoff triggers, the target agent takes over the conversation with its own system prompt and tools, inheriting the full message history. A "transfer_to_<Name>" tool is automatically registered on the source agent.
type HookAction ¶
type HookAction int
HookAction represents the action a hook wants to take on an intercepted event.
const ( HookAllow HookAction = iota HookDeny HookModify )
HookAction values control whether an event is allowed, denied, or modified.
type HookEvent ¶
type HookEvent struct {
Type HookEventType
Timestamp time.Time
AgentName string
TaskID string
Branch string
ToolCallID string
ToolName string
Input string
Output string
IsError bool
Duration time.Duration
Usage llm.TokenUsage
Error string
}
HookEvent is a structured record of an agent execution event emitted by observing hooks.
type HookEventType ¶
type HookEventType string
HookEventType identifies the kind of hook event being emitted.
const ( HookEventPreToolUse HookEventType = "pre_tool_use" HookEventPostToolUse HookEventType = "post_tool_use" HookEventPreModelCall HookEventType = "pre_model_call" HookEventPostModelCall HookEventType = "post_model_call" HookEventSubagentStart HookEventType = "subagent_start" HookEventSubagentStop HookEventType = "subagent_stop" HookEventToolError HookEventType = "tool_error" HookEventModelError HookEventType = "model_error" HookEventBeforeAgent HookEventType = "before_agent" HookEventAfterAgent HookEventType = "after_agent" HookEventBeforeRun HookEventType = "before_run" HookEventAfterRun HookEventType = "after_run" HookEventUserMessage HookEventType = "user_message" HookEventTeammateJoin HookEventType = "teammate_join" HookEventTeammateLeave HookEventType = "teammate_leave" HookEventTeamMessage HookEventType = "team_message" HookEventTeammateComplete HookEventType = "teammate_complete" HookEventTeammateError HookEventType = "teammate_error" )
HookEventType values for each stage of the agent execution pipeline.
type Hooks ¶
type Hooks struct {
PreToolUse func(ctx context.Context, tc ToolUseContext) (PreToolUseResult, error)
PostToolUse func(ctx context.Context, tc PostToolUseContext) (PostToolUseResult, error)
PreModelCall func(ctx context.Context, mc ModelCallContext) (ModelCallResult, error)
PostModelCall func(ctx context.Context, mc ModelResponseContext) (ModelResponseResult, error)
OnSubagentStart func(ctx context.Context, sc SubagentEventContext)
OnSubagentStop func(ctx context.Context, sc SubagentEventContext)
OnToolError func(ctx context.Context, tc ToolErrorContext) (ToolErrorResult, error)
OnModelError func(ctx context.Context, mc ModelErrorContext) (ModelErrorResult, error)
BeforeAgent func(ctx context.Context, ac LifecycleContext) (LifecycleResult, error)
AfterAgent func(ctx context.Context, ac LifecycleContext) (LifecycleResult, error)
BeforeRun func(ctx context.Context, rc RunContext)
AfterRun func(ctx context.Context, rc RunContext)
OnUserMessage func(ctx context.Context, uc UserMessageContext) (UserMessageResult, error)
OnEvent func(ctx context.Context, evt HookEvent)
OnTeammateJoin func(ctx context.Context, tc TeammateEventContext)
OnTeammateLeave func(ctx context.Context, tc TeammateEventContext)
OnTeamMessage func(ctx context.Context, mc TeamMessageContext)
OnTeammateComplete func(ctx context.Context, tc TeammateEventContext)
OnTeammateError func(ctx context.Context, tc TeammateEventContext)
}
Hooks defines callback functions that intercept and optionally modify agent execution events.
func NewObservingHooks ¶
NewObservingHooks creates a Hooks instance that emits read-only HookEvent records to fn.
type InstructionProvider ¶
InstructionProvider is a function that generates the system prompt dynamically.
type LifecycleContext ¶
type LifecycleContext struct {
AgentName string
TaskID string
Branch string
Input string
Response *ChatResponse
}
LifecycleContext provides context about an agent lifecycle event to before/after-agent hooks.
type LifecycleResult ¶
type LifecycleResult struct {
Action HookAction
Response *ChatResponse
}
LifecycleResult is the decision returned by a before/after-agent hook.
type ModelCallContext ¶
type ModelCallContext struct {
Messages []message.Message
Tools []tool.BaseTool
AgentName string
TaskID string
Branch string
}
ModelCallContext provides context about an upcoming LLM call to pre-model-call hooks.
type ModelCallResult ¶
type ModelCallResult struct {
Action HookAction
Messages []message.Message
Tools []tool.BaseTool
}
ModelCallResult is the decision returned by a pre-model-call hook.
type ModelErrorContext ¶
type ModelErrorContext struct {
Messages []message.Message
Tools []tool.BaseTool
Error error
AgentName string
TaskID string
Branch string
}
ModelErrorContext provides context about an LLM call failure to error-recovery hooks.
type ModelErrorResult ¶
type ModelErrorResult struct {
Action HookAction
Response *llm.Response
}
ModelErrorResult is the decision returned by a model-error hook.
type ModelResponseContext ¶
type ModelResponseContext struct {
Response *llm.Response
Duration time.Duration
AgentName string
TaskID string
Branch string
Error error
}
ModelResponseContext provides context about a completed LLM response to post-model-call hooks.
type ModelResponseResult ¶
type ModelResponseResult struct {
Action HookAction
Response *llm.Response
}
ModelResponseResult is the decision returned by a post-model-call hook.
type Option ¶
type Option func(*Agent)
Option is a functional option for configuring an Agent.
func WithAutoExecute ¶
WithAutoExecute controls whether tools are automatically executed when requested by the LLM. Default is true. Set to false for manual tool execution control.
func WithConfirmationProvider ¶
func WithConfirmationProvider(provider ConfirmationProvider) Option
WithConfirmationProvider sets a callback that decides whether sensitive tool calls should proceed. When set, tools with RequireConfirmation=true on their Info will invoke this callback before execution. Tools can also call tool.RequestConfirmation() from within Run() to trigger dynamic confirmation.
The provider blocks until a decision is made. For streaming, a confirmation event is emitted before the provider is called, allowing the consumer to present UI and then unblock the provider.
Example auto-approve:
agent.WithConfirmationProvider(func(ctx context.Context, req tool.ConfirmationRequest) (bool, error) {
return true, nil
})
func WithContextStrategy ¶
WithContextStrategy configures automatic context window management. When the conversation exceeds the token limit, the strategy trims messages to fit.
The maxContextTokens parameter sets the maximum tokens allowed for the conversation. When the conversation exceeds this limit, the strategy is applied.
Example with truncation:
agent.WithContextStrategy(truncate.Strategy(), 8000)
Example with sliding window:
agent.WithContextStrategy(sliding.Strategy(sliding.KeepLast(20)), 8000)
Example with summarization:
agent.WithContextStrategy(summarize.Strategy(summaryLLM), 8000)
func WithCoordinatorMode ¶
func WithCoordinatorMode() Option
WithCoordinatorMode restricts the lead agent to only team management and communication tools, preventing direct tool execution.
func WithFanOut ¶
func WithFanOut(configs ...FanOutConfig) Option
WithFanOut registers a fan-out tool that spawns multiple sub-agents in parallel. The LLM calls this tool with a list of tasks, and each task is dispatched to a separate execution of the template agent. Results are aggregated into a single response.
Note: The template agent should not use sessions, as concurrent Chat() calls would race.
func WithHandoffs ¶
func WithHandoffs(configs ...HandoffConfig) Option
WithHandoffs registers peer agents that this agent can transfer control to. When the LLM calls a transfer tool, the conversation continues with the new agent. The new agent inherits the full message history but uses its own system prompt and tools.
Handoff agents can themselves have handoffs, enabling chains like A -> B -> C.
func WithHooks ¶
WithHooks adds hook interceptors to the agent's execution pipeline. Hooks can observe, modify, or block tool calls and model interactions. Multiple calls append to the chain. Hooks run in registration order.
func WithInstructionProvider ¶
func WithInstructionProvider(provider InstructionProvider) Option
WithInstructionProvider sets a dynamic instruction provider that generates the system prompt at runtime. When set, this takes precedence over the static system prompt. The provider receives the current context and state map.
func WithMailbox ¶
WithMailbox overrides the team's default mailbox implementation. Must be called after WithTeam.
func WithMaxIterations ¶
WithMaxIterations sets the maximum number of tool execution iterations per chat. Default is 10. Prevents infinite loops when tools keep triggering more tool calls.
func WithMaxParallelTools ¶
WithMaxParallelTools sets the maximum number of tools that can execute concurrently. Default is 0 (unlimited). Set to a positive number to limit concurrency. This is useful when tools consume significant resources (e.g., API rate limits).
func WithMemory ¶
WithMemory sets the memory store for cross-conversation fact storage. The id parameter identifies the memory owner (e.g., user ID). When set, the agent automatically injects relevant memories into the system prompt. Use memory.AutoExtract() to enable automatic fact extraction from conversations. Use memory.AutoDedup() to enable LLM-based memory deduplication. Use memory.LLM() to set a separate LLM for memory operations.
func WithSequentialToolExecution ¶
func WithSequentialToolExecution() Option
WithSequentialToolExecution disables parallel tool execution. By default, tools are executed in parallel for better performance. Use this option when tools have dependencies on each other or when you need deterministic execution order.
func WithSession ¶
WithSession configures the agent with a session for conversation persistence. The session is automatically loaded if it exists, or created if it doesn't. If not called, the agent operates in stateless mode (no conversation history).
func WithState ¶
WithState sets the state map for template variable substitution in the system prompt. Use Go text/template syntax like {{.name}} in the system prompt, and they will be replaced with values from this state map. Supports conditionals, loops, and complex data.
func WithSubAgents ¶
func WithSubAgents(configs ...SubAgentConfig) Option
WithSubAgents registers child agents that the parent agent can invoke as tools. Each sub-agent appears as a callable tool to the LLM. When invoked, the sub-agent runs its own Chat() loop with a fresh context window and returns the result.
Sub-agents support background execution: the LLM can pass background: true to launch a sub-agent asynchronously and collect results later via the auto-registered get_task_result and stop_task tools.
Sub-agents do NOT inherit the parent's conversation history, tools, or system prompt. They operate as independent agents configured at creation time.
If the parent has hooks set, they are automatically propagated to sub-agents that do not already have their own hooks.
func WithSystemPrompt ¶
WithSystemPrompt sets the system prompt that defines the agent's behavior and personality.
func WithTeam ¶
WithTeam configures the agent as a team lead with the given team configuration. The team is created with a default in-memory channel mailbox and task board.
func WithTeammateTemplates ¶
WithTeammateTemplates registers pre-configured agent templates by name. When spawn_teammate is called with a matching name, the template is used instead of dynamically creating an agent.
func WithTools ¶
WithTools adds tools that the agent can use during conversations. Tools are executed automatically when the LLM requests them (unless WithAutoExecute is false).
func WithToolsets ¶
WithToolsets adds toolsets to the agent. Toolsets group tools under a name and support dynamic filtering — tools are resolved per-call via Toolset.Tools(ctx), not at creation time. Toolsets compose: a toolset can contain individual tools and other toolsets.
type PostToolUseContext ¶
type PostToolUseContext struct {
ToolUseContext
Output string
IsError bool
Duration time.Duration
}
PostToolUseContext provides context about a completed tool invocation to post-tool-use hooks.
type PostToolUseResult ¶
type PostToolUseResult struct {
Action HookAction
Output string
}
PostToolUseResult is the decision returned by a post-tool-use hook.
type PreToolUseResult ¶
type PreToolUseResult struct {
Action HookAction
DenyReason string
Input string
}
PreToolUseResult is the decision returned by a pre-tool-use hook.
type RunContext ¶
type RunContext struct {
AgentName string
TaskID string
Branch string
Input string
Response *ChatResponse
Error error
Duration time.Duration
}
RunContext provides context about a run lifecycle event to before/after-run hooks.
type SubAgentConfig ¶
type SubAgentConfig struct {
// Name is the tool name the parent agent uses to invoke this sub-agent.
Name string
// Description is the tool description shown to the LLM.
Description string
// Agent is the sub-agent instance that handles delegated tasks.
Agent *Agent
}
SubAgentConfig configures a sub-agent tool that the parent agent can delegate tasks to. Unlike handoffs, sub-agents run independently and return their result to the parent. They can run synchronously or in the background.
type SubagentEventContext ¶
type SubagentEventContext struct {
TaskID string
AgentName string
Task string
Branch string
Result string
Error error
Duration time.Duration
}
SubagentEventContext provides context about a sub-agent lifecycle event.
type TaskManager ¶
type TaskManager struct {
// contains filtered or unexported fields
}
TaskManager coordinates background sub-agent tasks. It tracks task lifecycle, supports blocking and non-blocking result retrieval with optional timeouts, and provides bulk cancellation for cleanup when the parent agent finishes.
func (*TaskManager) CancelAll ¶
func (tm *TaskManager) CancelAll()
CancelAll cancels every tracked background task.
func (*TaskManager) GetResult ¶
func (tm *TaskManager) GetResult( ctx context.Context, taskID string, wait bool, timeout time.Duration, ) (*BackgroundTask, error)
GetResult retrieves the current state of a background task. If wait is true, it blocks until the task completes or the timeout expires. A zero timeout means wait indefinitely.
func (*TaskManager) Launch ¶
func (tm *TaskManager) Launch( ctx context.Context, agentName string, a *Agent, task string, opts ...ChatOption, ) string
Launch starts a background task that runs the given agent with the provided task message. It returns a unique task ID that can be used with GetResult, Stop, or ListAll.
func (*TaskManager) ListAll ¶
func (tm *TaskManager) ListAll() []*BackgroundTask
ListAll returns a snapshot of all tracked background tasks regardless of status.
func (*TaskManager) Stop ¶
func (tm *TaskManager) Stop(taskID string) error
Stop cancels a running background task by its ID.
func (*TaskManager) WaitAll ¶
func (tm *TaskManager) WaitAll()
WaitAll blocks until every tracked background task has finished.
type TaskStatus ¶
type TaskStatus string
TaskStatus represents the lifecycle state of a background task.
const ( TaskRunning TaskStatus = "running" TaskCompleted TaskStatus = "completed" TaskFailed TaskStatus = "failed" TaskCancelled TaskStatus = "cancelled" )
Task status values.
type TeamMessageContext ¶
TeamMessageContext provides context about a message sent between team members.
type TeammateEventContext ¶
type TeammateEventContext struct {
TeamName string
MemberID string
MemberName string
Task string
Result string
Error error
Duration time.Duration
}
TeammateEventContext provides context about a teammate lifecycle event.
type ToolErrorContext ¶
type ToolErrorContext struct {
ToolUseContext
Error error
Output string
Duration time.Duration
}
ToolErrorContext provides context about a tool execution error to error-recovery hooks.
type ToolErrorResult ¶
type ToolErrorResult struct {
Action HookAction
Output string
}
ToolErrorResult is the decision returned by a tool-error hook.
type ToolExecutionResult ¶
type ToolExecutionResult struct {
// ToolCallID is the unique identifier for this tool call, matching the LLM's request.
ToolCallID string
// ToolName is the name of the tool that was executed.
ToolName string
// Input is the raw JSON input that was passed to the tool.
Input string
// Output is the tool's text response.
Output string
// IsError indicates whether the tool execution resulted in an error.
IsError bool
// Duration is the wall-clock time the tool execution took.
Duration time.Duration
}
ToolExecutionResult captures the outcome of a single tool invocation.
type ToolUseContext ¶
type ToolUseContext struct {
ToolCallID string
ToolName string
Input string
AgentName string
TaskID string
Branch string
}
ToolUseContext provides context about a tool invocation to pre-tool-use hooks.
type UserMessageContext ¶
UserMessageContext provides context about an incoming user message to input hooks.
type UserMessageResult ¶
type UserMessageResult struct {
Action HookAction
Message string
DenyReason string
}
UserMessageResult is the decision returned by a user-message hook.