Skip to main content
This guide walks you through creating a simple agent that can read files and run shell commands.

Create an Agent

1

Set up your project

Create a new project and install dependencies:
Set your API key:
2

Define the agent

Create an agent.ts file:
agent.ts
3

Run the agent

Add a simple loop that streams the agent’s output:
agent.ts

Add a Session for Multi-Turn Chat

For interactive conversations with automatic compaction and retry, wrap the agent in a Session:

Run the Examples

To run the examples, first clone and build the repository:
Then pick an example:
An interactive terminal agent with tool approval prompts and subagent display:
To use ChatGPT/Codex OAuth instead of OPENAI_API_KEY:
By default the examples use OPENAI_API_KEY. Create a .env file in the repo root:
The CLI example can instead use ChatGPT/Codex device login with --chatgpt.

Next Steps

Agents

Learn about the Agent API, events, and configuration options.

Sessions

Add compaction, retry, and persistence for multi-turn conversations.

Tools

Explore built-in tools and learn to create custom ones.