Class Definition
Unlike other context classes,
AgentContext is not abstract and provides a default execute() implementation that runs the agent loop.Type Parameters
Properties
Default Behavior
By default, agents run an automatic execution loop:- Builds user message from input
- Sends to LLM with available tools
- If LLM requests tool call, executes tool and sends result back
- Repeats until LLM returns final response
- Parses and returns output
Methods
Execution
execute(input)
Main execution method. Override for custom behavior.runAgentLoop().
runAgentLoop(input)
Run the default agent execution loop.Message Building (Overridable)
buildUserMessage(input)
Convert input to LLM message.parseAgentResponse(content)
Parse LLM response to output type.LLM Methods
completion(prompt, tools?, options?)
Generate LLM completion.streamCompletion(prompt, tools?)
Stream LLM completion.Tool Execution
executeTool(name, args)
Execute a tool by name.invokeAgent(agentId, input)
Invoke another agent.Notifications
notify(message, level?)
Send log message notification.progress(progress, total?, message?)
Send progress notification.Elicitation
elicit<S>(message, requestedSchema, options?)
Request interactive user input.Custom Agent Example
Multi-Agent Orchestration
Full Example
Related
@Agent
Agent decorator
AgentRegistry
Agent registry
Agent Errors
Agent errors
@Tool
Tool decorator