Skip to content

Commit 52eb3f9

Browse files
Improve Human-In-The-Loop (#103)
* wip * fix(interruptions): avoid infinite loop. add interruptions helper * mostly working experience * fix(interruptions): avoid double counting tool calls * add some comments * docs(nextjs): improve documentation * fix build
1 parent ef64938 commit 52eb3f9

38 files changed

+1811
-15
lines changed

.changeset/dark-melons-go.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openai/agents-core': patch
3+
---
4+
5+
fix(interruptions): avoid double outputting function calls for approval requests

.changeset/weak-views-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openai/agents-core': patch
3+
---
4+
5+
fix(interruptions): avoid accidental infinite loop if all interruptions were not cleared. expose interruptions helper on state

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default tseslint.config(
2222
'**/docs/.astro/**',
2323
'examples/realtime-next/**',
2424
'examples/realtime-demo/**',
25+
'examples/nextjs/**',
2526
'integration-tests//**',
2627
]),
2728
eslint.configs.recommended,

examples/nextjs/.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
.env*
35+
36+
# vercel
37+
.vercel
38+
39+
# typescript
40+
*.tsbuildinfo
41+
next-env.d.ts

examples/nextjs/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Next.js Demo
2+
3+
This example shows a basic example of how to use human-in-the-loop in a Next.js application.
4+
5+
Right now it only uses a synchronous approach without streaming and storing in an in-memory DB.
6+
7+
Eventually we will add more examples.
8+
9+
## Run the example
10+
11+
Set the `OPENAI_API_KEY` environment variable and run:
12+
13+
```bash
14+
pnpm -F nextjs dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) in your browser and ask `What is the weather in San Francisco and Oakland?`
18+
19+
## Endpoints
20+
21+
- **`/`** – The basic example that actually handles receiving the approval requests and sending messages to the API. Code in `src/app/page.tsx`.
22+
- **`/api/basic`** – The endpoint that gets triggered to run the agent. Code in `src/app/websocket/page.tsx`.
23+
24+
## Other files
25+
26+
- `src/components/Approvals.tsx` — renders the approval dialog
27+
- `src/agents.ts` — contains the basic Agent configuration
28+
- `src/db.ts` — contains the mock database implementation

examples/nextjs/components.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "new-york",
4+
"rsc": true,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "",
8+
"css": "src/app/globals.css",
9+
"baseColor": "neutral",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"aliases": {
14+
"components": "@/components",
15+
"utils": "@/lib/utils",
16+
"ui": "@/components/ui",
17+
"lib": "@/lib",
18+
"hooks": "@/hooks"
19+
},
20+
"iconLibrary": "lucide"
21+
}

examples/nextjs/next.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { NextConfig } from 'next';
2+
3+
const nextConfig: NextConfig = {
4+
/* config options here */
5+
};
6+
7+
export default nextConfig;

examples/nextjs/package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "nextjs",
3+
"private": true,
4+
"scripts": {
5+
"dev": "next dev --turbopack",
6+
"build": "next build",
7+
"start": "next start",
8+
"lint": "next lint",
9+
"build-check": "tsc --noEmit"
10+
},
11+
"dependencies": {
12+
"@openai/agents": "workspace:*",
13+
"@radix-ui/react-dialog": "^1.1.14",
14+
"@radix-ui/react-slot": "^1.2.3",
15+
"@tanstack/react-query": "^5.80.7",
16+
"class-variance-authority": "^0.7.1",
17+
"clsx": "^2.1.1",
18+
"lucide-react": "^0.515.0",
19+
"next": "15.3.2",
20+
"react": "^19.0.0",
21+
"react-dom": "^19.0.0",
22+
"tailwind-merge": "^3.3.1",
23+
"wavtools": "^0.1.5",
24+
"zod": "~3.25.40"
25+
},
26+
"devDependencies": {
27+
"@tailwindcss/postcss": "^4",
28+
"@types/node": "^20",
29+
"@types/react": "^19",
30+
"@types/react-dom": "^19",
31+
"tailwindcss": "^4",
32+
"tw-animate-css": "^1.3.4",
33+
"typescript": "^5"
34+
}
35+
}

examples/nextjs/postcss.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const config = {
2+
plugins: ['@tailwindcss/postcss'],
3+
};
4+
5+
export default config;

examples/nextjs/public/file.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)