Agent combines a model, instructions, tools, and limits. Give it a task and the SDK runs the model/tool loop until the model finishes or a limit stops it. Cognitio starts its bundled runtime automatically; you do not need a separate CLI installation.
An Agent is a reusable configuration, not a conversation. Each run() or stream() starts a new session. Use sessions when later messages should remember earlier ones.
Run a task
This complete example checks the provider key, sends a short prompt, validates the terminal outcome, and closes its runtime. The explicitspawn.env supplies the key and gives this Agent its own local runtime. Isolation is already enabled by default.
disallowedTools: ["*"] makes this a text-only task. Remove it or choose a nonempty allowedTools list when the task needs built-in tools or your own functions.
Run the examples
The guides use TypeScript with top-levelawait. In a Node.js 22 project, install:
agent.ts. Create a .env file containing your OPENAI_API_KEY, add .env to .gitignore, then run:
maxBudgetUsd is an estimated stopping threshold, not a prepaid spending cap.
Choose an API
For example, a second
agent.run("What did I just ask?") does not see the first run. Configuration is shared, conversation history is not. Separate sessions can run concurrently; a single session accepts one active query at a time.
Check completion, not just transport success
agent.run() returns a RunResult: text, isError, subtype, session identifiers, turn count, duration, and optional usage/cost/structured output. A completed request can still have an unsuccessful terminal result.
Setup, connection, and lifecycle errors can also throw. Keep cleanup in
finally, including when you reject a terminal result.
One-shot query
This alternative owns and closes its temporary Agent. Supplyingspawn gives it a dedicated runtime that closes when iteration finishes, throws, or is returned early.
Runtime ownership
Explicit
control or workspaceId connection options also select a dedicated local client when no baseUrl or injected client is supplied. The Agent closes that dedicated client.
Local isolation separates runtime configuration, credentials, and state from your usual installation. It does not sandbox tool access to files, processes, or the network. Choose tool permissions for the work your application permits. For service shutdown patterns, see lifecycle.