Skip to main content

Agent class

The Agent class is the core class in Agenite that orchestrates interactions between LLMs and tools.

Constructor

Parameters

  • name (required): Unique identifier for the agent
  • provider (required): LLM provider instance
  • tools: Array of tools available to the agent
  • instructions: System instructions for the agent (default: “You are a helpful assistant.”)
  • description: Description of the agent’s purpose
  • agents: Sub-agents that can be called by this agent
  • stateReducer: Custom state management functions
  • initialState: Initial agent state
  • steps: Custom execution steps
  • startStep: First step to execute (default: “agenite.llm-call”)
  • middlewares: Array of middleware functions to modify agent behavior
  • extensions: Additional custom functionality

Methods

execute

Execute the agent with a set of inputs.
Parameters
  • input (required): Input state, typically containing messages
  • options: Additional execution options
    • stream: Enable streaming responses
    • context: Additional execution context
    • parentExecution: Context from a parent execution (for nested agents)
Returns
Returns the final state object containing:
  • messages: Array of messages from the conversation
  • tokenUsage: Token usage statistics
  • Additional properties from the state

iterate

Get an iterator for streaming responses.
Parameters
Same as execute
Returns
An AsyncGenerator that yields various events during execution:

State and Messages

State Structure

The agent maintains state which typically includes at minimum:

Message Structure

Messages follow the structure defined in the LLM package:

Step Interface

Custom steps implement the Step interface:

Middleware Interface

Middlewares wrap the generator function:

Examples

Basic usage

With custom state

With middleware

With custom steps

Next steps