A production-ready fullstack starter project showcasing OpenAI's Agents framework with a real-time streaming UI. Built with Next.js, TypeScript, and WebSockets.
- Multi-Agent System - Seamless agent-to-agent handoffs
- Real-time Streaming - Live updates via WebSocket connection
- Tool Approvals - Built-in approval system for sensitive operations
- Modern UI - Clean, responsive interface with Tailwind CSS
- Type-Safe - Full TypeScript support throughout
- Example Tools - Weather API, email management with mock data
- General Agent - Handles general requests (weather information)
- Mail Agent - Manages email operations (read inbox, send emails)
The agents communicate through a simple handoff system: General Agent → Mail Agent
get-weather
- Fetches weather information for a locationget-mails
- Retrieves emails from inbox (returns 3 example emails)send-mail
- Sends an email (requires approval)
- Node.js 18+
- npm, yarn, pnpm, or bun
- OpenAI API key
- Clone the repository:
git clone <your-repo-url>
cd openai-agents-js-ui-stream
- Install dependencies:
npm install
- Create a
.env
file in the root directory:
OPENAI_API_KEY=your_openai_api_key_here
- Run the development server:
npm run dev
This will start both:
- Next.js frontend at http://localhost:3000
- WebSocket server at
ws://localhost:8787
You can also run the frontend and backend separately:
# Terminal 1 - Frontend
npm run dev:next
# Terminal 2 - Backend
npm run dev:server
├── src/
│ ├── app/ # Next.js app directory
│ │ ├── page.tsx # Main page component
│ │ ├── layout.tsx # Root layout
│ │ └── globals.css # Global styles
│ └── ui/ # UI components
│ ├── ChatFeed.tsx # Message display
│ ├── Composer.tsx # Message input
│ ├── Approvals.tsx # Approval system UI
│ ├── OperationsPanel.tsx # Operations sidebar
│ ├── Timeline.tsx # Event timeline
│ └── useRunWS.tsx # WebSocket hook
├── server.ts # WebSocket server & agent setup
├── package.json
└── README.md
- Next.js 15 - React framework
- React 19 - UI library
- Tailwind CSS 4 - Styling
- TypeScript - Type safety
- OpenAI Agents - Agent framework
- WebSocket (ws) - Real-time communication
- Zod - Schema validation
- tsx - TypeScript execution
Edit server.ts
to add new tools:
const yourTool = tool({
name: 'your-tool',
description: 'Description of your tool',
execute: async ({ param }) => ({
result: 'your result'
}),
parameters: z.object({
param: z.string(),
}),
needsApproval: false, // Set to true for approval requirement
});
Create a new agent in server.ts
:
const yourAgent = new Agent({
name: 'your-agent',
instructions: 'What your agent does',
tools: [yourTool],
model,
});
Update handoffs in server.ts
:
generalAgent.handoffs.push(handoff(yourAgent));
- Open the app at http://localhost:3000
- Type a message like "What's the weather in London?"
- The general agent will use the
get-weather
tool - Try "Show my emails" to see the mail agent in action
- Try "Send an email to john@example.com" to trigger an approval request
Contributions are welcome! Feel free to open issues or submit pull requests.
For questions or feedback, reach out:
Yusuf Eren
Email: erenyusuf170@gmail.com
This project is open source and available under the MIT License.
- Built with OpenAI Agents
- UI inspired by modern chat interfaces
- Bootstrapped with create-next-app