Function: agent()
@providerprotocol/agents / index / agent
Function: agent()
Section titled “Function: agent()”agent(
options):Agent
Defined in: src/agent/index.ts:86
Creates a new agent instance with the specified configuration.
The agent factory function is the primary entry point for creating AI agents
in the Unified Agent Protocol (UAP). It combines an LLM from @providerprotocol/ai
with UAP-specific features like state management, middleware, and execution strategies.
Parameters
Section titled “Parameters”options
Section titled “options”Agent configuration options including model, tools, system prompt, execution strategy, middleware, and checkpointing configuration
Returns
Section titled “Returns”A configured Agent instance ready for execution
Remarks
Section titled “Remarks”The agent function performs the following setup:
- Generates a unique agent ID (UUIDv4)
- Optionally generates a session ID for checkpointing
- Creates the underlying LLM instance with full UPP passthrough
- Configures the middleware pipeline
- Sets up the execution strategy (defaults to
loop())
Examples
Section titled “Examples”Basic agent creation:
import { agent, AgentState } from '@providerprotocol/agents';import { anthropic } from '@providerprotocol/ai/anthropic';
const myAgent = agent({ model: anthropic('claude-sonnet-4-20250514'), system: 'You are a helpful assistant.',});
const state = AgentState.initial();const { turn, state: newState } = await myAgent.generate('Hello', state);Agent with tools and middleware:
import { agent } from '@providerprotocol/agents';import { anthropic } from '@providerprotocol/ai/anthropic';import { loop } from '@providerprotocol/agents/execution';import { withContext } from '@providerprotocol/agents/middleware';
const coder = agent({ model: anthropic('claude-sonnet-4-20250514'), tools: [Bash, Read, Write], system: 'You are a coding assistant.', execution: loop({ maxIterations: 20 }), middleware: [withContext({ maxTokens: 100000 })],});- Agent for the returned interface
- AgentOptions for all configuration options