Skip to content

Commit efcdfa7

Browse files
authored
Add OpenAI Agents example with TS (#327)
Add OpenAI Agents example with ts
1 parent 10ef1e8 commit efcdfa7

File tree

3 files changed

+553
-8
lines changed

3 files changed

+553
-8
lines changed

pages/home/oai-agents/overview.mdx

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,39 @@
22
title: "Arcade with OpenAI Agents overview"
33
description: "Comprehensive guide to using Arcade with the OpenAI Agents library"
44
---
5+
import { Steps, Tabs } from "nextra/components";
6+
57

68
# Arcade with OpenAI Agents
79

8-
The `agents-arcade` package provides a seamless integration between [Arcade](https://arcade.dev) and the [OpenAI Agents Library](https://github.com/openai/openai-python). This integration allows you to enhance your AI agents with powerful Arcade tools including Google Mail, LinkedIn, GitHub, and many more.
10+
Arcade provides seamless integration with the [OpenAI Agents Library](https://github.com/openai/openai-python) and [OpenAI Agents JS](https://openai.github.io/openai-agents-js/), allowing you to enhance your AI agents with powerful tools including Gmail, LinkedIn, GitHub, and many more. This integration is available through the `agents-arcade` package for Python and our [JavaScript client library](https://github.com/ArcadeAI/arcade-js).
911

1012
## Installation
1113

1214
Install the necessary packages to get started:
1315

16+
<Tabs items={["Python", "JavaScript"]} storageKey="preferredLanguage">
17+
<Tabs.Tab>
18+
1419
```bash
1520
pip install agents-arcade arcadepy
1621
```
1722

23+
</Tabs.Tab>
24+
25+
<Tabs.Tab>
26+
27+
```bash
28+
npm install @openai/agents @arcadeai/arcadejs
29+
```
30+
31+
</Tabs.Tab>
32+
33+
</Tabs>
34+
1835
Make sure you have your Arcade API key ready. [Get an API key](/home/api-keys) if you don't already have one.
1936

37+
2038
## Key features
2139

2240
- **Easy integration** with the OpenAI Agents framework
@@ -29,6 +47,9 @@ Make sure you have your Arcade API key ready. [Get an API key](/home/api-keys) i
2947

3048
Here's a simple example of using Arcade tools with OpenAI Agents:
3149

50+
<Tabs items={["Python", "JavaScript"]} storageKey="preferredLanguage">
51+
<Tabs.Tab>
52+
3253
```python
3354
from agents import Agent, Runner
3455
from arcadepy import AsyncArcade
@@ -66,8 +87,65 @@ if __name__ == "__main__":
6687
asyncio.run(main())
6788
```
6889

90+
</Tabs.Tab>
91+
92+
<Tabs.Tab>
93+
94+
Check out the complete working example in our [GitHub repository](https://github.com/ArcadeAI/arcade-ai/tree/main/examples/openai-agents-ts/src/index.ts).
95+
96+
```javascript
97+
import Arcade from '@arcadeai/arcadejs';
98+
import { executeOrAuthorizeZodTool, toZod } from "@arcadeai/arcadejs/lib";
99+
import { Agent, run, tool } from '@openai/agents';
100+
101+
// 1) Initialize Arcade client
102+
const client = new Arcade();
103+
104+
// 2) Fetch Google toolkit from Arcade and prepare tools for OpenAI Agents
105+
const googleToolkit = await client.tools.list({ toolkit: "google", limit: 30 });
106+
const arcadeTools = toZod({
107+
tools: googleToolkit.items,
108+
client,
109+
userId: "<YOUR_SYSTEM_USER_ID>", // Replace this with your application's user ID (e.g. email address, UUID, etc.)
110+
executeFactory: executeOrAuthorizeZodTool,
111+
})
112+
113+
// 3) Convert the tools to a format that OpenAI Agents can use
114+
const tools = arcadeTools.map(({ name, description, execute, parameters }) =>
115+
tool({
116+
name,
117+
description: description ?? "",
118+
parameters: parameters as any,
119+
execute,
120+
strict: true,
121+
}),
122+
);
123+
124+
// 4) Create a new agent with the Google toolkit
125+
const googleAgent = new Agent({
126+
name: "Google agent",
127+
instructions: "You are a helpful assistant that can assist with Google API calls.",
128+
model: "gpt-4o-mini",
129+
tools
130+
});
131+
132+
// 5) Run the agent
133+
const result = await run(googleAgent, "What are my latest emails?");
134+
135+
// 6) Print the result
136+
console.log(result.finalOutput);
137+
```
138+
139+
</Tabs.Tab>
140+
141+
</Tabs>
142+
143+
69144
## Handling authorization
70145

146+
<Tabs items={["Python", "JavaScript"]} storageKey="preferredLanguage">
147+
<Tabs.Tab>
148+
71149
When a user needs to authorize access to a tool (like Google or GitHub), the agent will raise an `AuthorizationError` with a URL for the user to visit:
72150

73151
```python
@@ -79,6 +157,20 @@ except AuthorizationError as e:
79157
print(f"Please visit this URL to authorize: {e}")
80158
```
81159

160+
</Tabs.Tab>
161+
162+
<Tabs.Tab>
163+
164+
When a user needs to authorize access to a tool (like Google or GitHub), the agent will show a message like this:
165+
166+
```bash
167+
[Authorize Gmail Access](https://accounts.google.com/o/oauth2/v2/auth?access_type=offline...)
168+
Once you have authorized access, I can retrieve your latest emails.
169+
```
170+
171+
</Tabs.Tab>
172+
</Tabs>
173+
82174
After visiting the URL and authorizing access, the user can run the agent again with the same `user_id`, and it will work without requiring re-authorization.
83175

84176
## Available toolkits

0 commit comments

Comments
 (0)