Skip to main content
You will build a small Node.js program that asks an agent a question and prints its answer. You need Node.js 22 or newer, npm, and an OpenAI API key with access to the model used below. See installation for supported operating systems and other package managers.

1. Create a project

The package includes the matching native runtime through npm optional dependencies. Keep optional dependencies enabled; no separate runtime installation is needed.

2. Add your API key

Create a file named .env in this directory:
Create .gitignore so your key and installed packages stay out of source control:
The run command below uses Node’s --env-file option to load .env. Cognitio can also use provider variables already set in your shell. To use another provider, change the key and model together; see models and prompts.

3. Write the agent

Create agent.mjs:
agent.mjs
  • model selects the provider and model as provider/model.
  • instructions describes the behavior you want to reuse across tasks.
  • disallowedTools: ["*"] makes this a text-only first run.
  • maxTurns limits model turns within one task.
  • run() returns the final answer and run metadata.
  • shutdown() releases the shared local runtime when this script is finished.

4. Run it

You should see a short explanation of how a model selects a tool and uses its result. The exact wording varies. When the response is complete, the script exits. No extra isolation setup is required: the SDK starts with its own runtime configuration and temporary state. It does not automatically load your personal agent configuration. This is configuration isolation, not an operating-system sandbox for tools. If the program fails, start with missing credentials, runtime installation, or a process that stays alive.

5. Give it a useful next task

The rest of the guides use TypeScript where types help explain an API. You can run those examples with the TypeScript setup.