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 aSession:
Run the Examples
To run the examples, first clone and build the repository:- CLI
- Next.js
- Nuxt
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 The CLI example can instead use ChatGPT/Codex device login with
OPENAI_API_KEY. Create a .env file in the repo root:--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.