Skip to content

Commit 5610a01

Browse files
authored
Update docs for OpenAI Agents (#331)
1 parent 0da46a0 commit 5610a01

File tree

3 files changed

+40
-88
lines changed

3 files changed

+40
-88
lines changed

pages/home/oai-agents/overview.mdx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,36 +103,25 @@ const client = new Arcade();
103103

104104
// 2) Fetch Google toolkit from Arcade and prepare tools for OpenAI Agents
105105
const googleToolkit = await client.tools.list({ toolkit: "google", limit: 30 });
106-
const arcadeTools = toZod({
106+
const tools = toZod({
107107
tools: googleToolkit.items,
108108
client,
109109
userId: "<YOUR_SYSTEM_USER_ID>", // Replace this with your application's user ID (e.g. email address, UUID, etc.)
110110
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
111+
}).map(tool);
112+
113+
// 3) Create a new agent with the Google toolkit
125114
const googleAgent = new Agent({
126115
name: "Google agent",
127116
instructions: "You are a helpful assistant that can assist with Google API calls.",
128117
model: "gpt-4o-mini",
129118
tools
130119
});
131120

132-
// 5) Run the agent
121+
// 4) Run the agent
133122
const result = await run(googleAgent, "What are my latest emails?");
134123

135-
// 6) Print the result
124+
// 5) Print the result
136125
console.log(result.finalOutput);
137126
```
138127

pages/home/oai-agents/use-arcade-tools.mdx

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,12 @@ const specificTools = await Promise.all([
125125

126126
// Convert any of the above to OpenAI Agents format
127127
const convertToAgents = (arcadeTools) => {
128-
const zodTools = toZod({
128+
return toZod({
129129
tools: arcadeTools,
130130
client,
131131
userId: "<YOUR_SYSTEM_USER_ID>", // Replace this with your application's user ID (e.g. email address, UUID, etc.)
132132
executeFactory: executeOrAuthorizeZodTool,
133-
});
134-
135-
return zodTools.map(({ name, description, execute, parameters }) =>
136-
tool({
137-
name,
138-
description: description ?? "",
139-
parameters: parameters as any,
140-
execute,
141-
strict: true,
142-
})
143-
);
133+
}).map(tool);
144134
};
145135

146136
// Use with any of the options above
@@ -312,36 +302,25 @@ const client = new Arcade();
312302

313303
// 2) Fetch Google toolkit from Arcade and prepare tools for OpenAI Agents
314304
const googleToolkit = await client.tools.list({ toolkit: "google", limit: 30 });
315-
const arcadeTools = toZod({
305+
const tools = toZod({
316306
tools: googleToolkit.items,
317307
client,
318308
userId: "<YOUR_SYSTEM_USER_ID>", // Replace this with your application's user ID (e.g. email address, UUID, etc.)
319309
executeFactory: executeOrAuthorizeZodTool,
320-
})
321-
322-
// 3) Convert the tools to a format that OpenAI Agents can use
323-
const tools = arcadeTools.map(({ name, description, execute, parameters }) =>
324-
tool({
325-
name,
326-
description: description ?? "",
327-
parameters: parameters as any,
328-
execute,
329-
strict: true,
330-
}),
331-
);
332-
333-
// 4) Create a new agent with the Google toolkit
310+
}).map(tool);
311+
312+
// 3) Create a new agent with the Google toolkit
334313
const googleAgent = new Agent({
335314
name: "Google agent",
336315
instructions: "You are a helpful assistant that can assist with Google API calls.",
337316
model: "gpt-4o-mini",
338317
tools
339318
});
340319

341-
// 5) Run the agent
320+
// 4) Run the agent
342321
const result = await run(googleAgent, "What are my latest emails?");
343322

344-
// 6) Print the result
323+
// 5) Print the result
345324
console.log(result.finalOutput);
346325
```
347326

pages/home/oai-agents/user-auth-interrupts.mdx

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,21 @@ This automatically returns authorization URLs instead of throwing errors.
179179
```javascript
180180
import { isAuthorizationRequiredError } from "@arcadeai/arcadejs/lib";
181181

182-
const tools = arcadeTools.map(({ name, description, execute, parameters }) =>
183-
tool({
184-
name,
185-
description: description ?? "",
186-
parameters: parameters as any,
187-
execute,
188-
errorFunction: async(_, error) => {
189-
if (error instanceof Error && isAuthorizationRequiredError(error)) {
190-
const response = await client.tools.authorize({
191-
tool_name: name,
192-
user_id: "<YOUR_SYSTEM_USER_ID_2>",
193-
});
194-
return `Please login to Google: ${response.url}`;
195-
}
196-
return "Error executing tool"
197-
}
198-
}),
199-
);
182+
const tools = arcadeTools.map((arcadeTool) => {
183+
return tool({
184+
...arcadeTool,
185+
errorFunction: async (_, error) => {
186+
if (error instanceof Error && isAuthorizationRequiredError(error)) {
187+
const response = await client.tools.authorize({
188+
tool_name: arcadeTool.name,
189+
user_id: "<YOUR_SYSTEM_USER_ID>",
190+
});
191+
return `Please login to Google: ${response.url}`;
192+
}
193+
return "Error executing tool"
194+
}
195+
})
196+
});
200197
```
201198
</Tabs.Tab>
202199

@@ -260,15 +257,12 @@ To wait for authorization completion, follow this approach:
260257

261258

262259
```javascript
263-
const tools = arcadeTools.map(({ name, description, execute, parameters }) =>
264-
tool({
265-
name,
266-
description: description ?? "",
267-
parameters: parameters as any,
268-
execute,
269-
errorFunction: (_, error) => { throw error } // Throw the error to the agent for handling
270-
}),
271-
);
260+
const tools = arcadeTools.map((arcadeTool) => {
261+
return tool({
262+
...arcadeTool,
263+
errorFunction: (_, error) => { throw error } // Throw the error to the agent for handling
264+
})
265+
});
272266

273267
while (true) {
274268
try {
@@ -374,31 +368,21 @@ async function main() {
374368

375369
// 2) Fetch Google toolkit from Arcade and prepare tools for OpenAI Agents
376370
const googleToolkit = await client.tools.list({ toolkit: "google", limit: 30 });
377-
const arcadeTools = toZod({
371+
const tools = toZod({
378372
tools: googleToolkit.items,
379373
client,
380374
userId: "<YOUR_SYSTEM_USER_ID_2>", // Replace this with your application's user ID (e.g. email address, UUID, etc.)
381-
})
375+
}).map(tool);
382376

383-
// 3) Convert the tools to a format that OpenAI Agents can use
384-
const tools = arcadeTools.map(({ name, description, execute, parameters }) =>
385-
tool({
386-
name,
387-
description: description ?? "",
388-
parameters: parameters as any,
389-
execute,
390-
errorFunction: (_, error) => { throw error }
391-
}),
392-
);
393-
394-
// 4) Create a new agent with the Google toolkit
377+
// 3) Create a new agent with the Google toolkit
395378
const googleAgent = new Agent({
396379
name: "Google agent",
397380
instructions: "You are a helpful assistant that can assist with Google API calls.",
398381
model: "gpt-4o-mini",
399382
tools
400383
});
401384

385+
// 4) Run the agent, if authorization is required, wait for it to complete and retry
402386
while (true) {
403387
try {
404388
const result = await run(googleAgent, "What are my latest emails?");
@@ -413,7 +397,7 @@ async function main() {
413397
if (response.status !== "completed") {
414398
console.log(`Please complete the authorization challenge in your browser: ${response.url}`);
415399
}
416-
400+
417401
// Wait for the authorization to complete
418402
await client.auth.waitForCompletion(response);
419403
console.log("Authorization completed, retrying...");

0 commit comments

Comments
 (0)