Skip to main content

Function: agent()

agent(opts): Agent

Defined in: packages/agentos/src/api/agent.ts:479

Creates a lightweight stateful agent backed by in-memory session storage.

The agent wraps generateText and streamText with a persistent system prompt built from instructions, name, and personality fields. Multiple independent sessions can be opened via Agent.session().

Parameters

opts

AgentOptions

Agent configuration including model, instructions, and optional tools. All BaseAgentConfig fields are accepted; advanced fields (rag, discovery, permissions, emergent, voice, guardrails, etc.) are stored but not actively wired in the lightweight layer — they are consumed by agency() and the full runtime.

Returns

Agent

An Agent instance with generate, stream, session, and close methods.

Example

const myAgent = agent({ model: 'openai:gpt-4o', instructions: 'You are a helpful assistant.' });
const session = myAgent.session('user-123');
const reply = await session.send('Hello!');
console.log(reply.text);