Skip to content

Function: agent()

@providerprotocol/agents


@providerprotocol/agents / index / 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.

AgentOptions

Agent configuration options including model, tools, system prompt, execution strategy, middleware, and checkpointing configuration

Agent

A configured Agent instance ready for execution

The agent function performs the following setup:

  1. Generates a unique agent ID (UUIDv4)
  2. Optionally generates a session ID for checkpointing
  3. Creates the underlying LLM instance with full UPP passthrough
  4. Configures the middleware pipeline
  5. Sets up the execution strategy (defaults to loop())

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 })],
});