Skip to main content

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:
The default loop:
  1. Builds user message from input
  2. Sends to LLM with available tools
  3. If LLM requests tool call, executes tool and sends result back
  4. Repeats until LLM returns final response
  5. Parses and returns output

Methods

Execution

execute(input)

Main execution method. Override for custom behavior.
Default implementation calls 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

@Agent

Agent decorator

AgentRegistry

Agent registry

Agent Errors

Agent errors

@Tool

Tool decorator