1. Install Cognitio
Use Node.js 22 or newer. In your application directory:2. Replace a one-task call
Create.env with your Anthropic key and keep it out of Git:
agent.mjs:
spawn option makes this Agent own a dedicated runtime, so close() stops it. The estimated budget does not guarantee a provider billing ceiling.
For a complete OpenAI version, follow the chat recipe or open the chat application source.
3. Map the features your application uses
Use
provider/model identifiers such as anthropic/claude-sonnet-4-5. Built-in tool names are Cognitio names such as read, grep and glob; a direct custom tool named multiply is exposed as sdk_multiply.
Rewrite message handling against the AgentMessage union. An event with type: "result" contains its terminal result in message.result; partial text is opt-in. Do not reuse another SDK’s message parser unchanged.
Check these behavior differences
- Configuration: local runtimes isolate state by default and sessions use
settingSources: []. Opt into local instruction discovery deliberately. - Tools:
allowedTools: []leaves the allowlist unrestricted. UsedisallowedTools: ["*"]for text-only work. Custom tool input must be validated insideexecute. - Permissions: explicit rules and modes can decide before
canUseTool. A callback is not an interceptor for every tool call. - Lifecycle: default Agents share a process-wide runtime until
shutdown(). Agents with explicitspawnoptions close their own runtime; injected clients are borrowed. - Persistence: an isolated runtime’s transcript disappears with its temporary state. Reuse a persistent runtime when sessions must survive application restarts.
- Hooks and reasoning: use Cognitio’s documented hook names and provider-specific reasoning options. Matching names in another SDK do not guarantee matching semantics.