Skip to main content

Function: agent()

agent(opts): Agent

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

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().

With runtime: 'gmi', agent(opts) returns gmi(opts): the same Agent surface, with every session served by a Generalized Mind Instance built from these options, and the construction checks and diagnostics of that path.

Parameters​

opts​

AgentOptions

Agent configuration. Deferred fields are reported at construction. Voice is applied only through an explicit voice.session binding and the returned voiceSession() method. Ordinary generate/stream/session calls remain text calls. The full runtime does not apply the voice flag.

Returns​

Agent

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

Throws​

With runtime: 'gmi', at construction, naming an option the GMI path cannot honour (see gmi); without it, when agencies.launch is set, which only the GMI path runs.

Example​

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