Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions pages/home/oai-agents/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,36 +103,25 @@ const client = new Arcade();

// 2) Fetch Google toolkit from Arcade and prepare tools for OpenAI Agents
const googleToolkit = await client.tools.list({ toolkit: "google", limit: 30 });
const arcadeTools = toZod({
const tools = toZod({
tools: googleToolkit.items,
client,
userId: "<YOUR_SYSTEM_USER_ID>", // Replace this with your application's user ID (e.g. email address, UUID, etc.)
executeFactory: executeOrAuthorizeZodTool,
})

// 3) Convert the tools to a format that OpenAI Agents can use
const tools = arcadeTools.map(({ name, description, execute, parameters }) =>
tool({
name,
description: description ?? "",
parameters: parameters as any,
execute,
strict: true,
}),
);

// 4) Create a new agent with the Google toolkit
}).map(tool);

// 3) Create a new agent with the Google toolkit
const googleAgent = new Agent({
name: "Google agent",
instructions: "You are a helpful assistant that can assist with Google API calls.",
model: "gpt-4o-mini",
tools
});

// 5) Run the agent
// 4) Run the agent
const result = await run(googleAgent, "What are my latest emails?");

// 6) Print the result
// 5) Print the result
console.log(result.finalOutput);
```

Expand Down
37 changes: 8 additions & 29 deletions pages/home/oai-agents/use-arcade-tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,12 @@ const specificTools = await Promise.all([

// Convert any of the above to OpenAI Agents format
const convertToAgents = (arcadeTools) => {
const zodTools = toZod({
return toZod({
tools: arcadeTools,
client,
userId: "<YOUR_SYSTEM_USER_ID>", // Replace this with your application's user ID (e.g. email address, UUID, etc.)
executeFactory: executeOrAuthorizeZodTool,
});

return zodTools.map(({ name, description, execute, parameters }) =>
tool({
name,
description: description ?? "",
parameters: parameters as any,
execute,
strict: true,
})
);
}).map(tool);
};

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

// 2) Fetch Google toolkit from Arcade and prepare tools for OpenAI Agents
const googleToolkit = await client.tools.list({ toolkit: "google", limit: 30 });
const arcadeTools = toZod({
const tools = toZod({
tools: googleToolkit.items,
client,
userId: "<YOUR_SYSTEM_USER_ID>", // Replace this with your application's user ID (e.g. email address, UUID, etc.)
executeFactory: executeOrAuthorizeZodTool,
})

// 3) Convert the tools to a format that OpenAI Agents can use
const tools = arcadeTools.map(({ name, description, execute, parameters }) =>
tool({
name,
description: description ?? "",
parameters: parameters as any,
execute,
strict: true,
}),
);

// 4) Create a new agent with the Google toolkit
}).map(tool);

// 3) Create a new agent with the Google toolkit
const googleAgent = new Agent({
name: "Google agent",
instructions: "You are a helpful assistant that can assist with Google API calls.",
model: "gpt-4o-mini",
tools
});

// 5) Run the agent
// 4) Run the agent
const result = await run(googleAgent, "What are my latest emails?");

// 6) Print the result
// 5) Print the result
console.log(result.finalOutput);
```

Expand Down
68 changes: 26 additions & 42 deletions pages/home/oai-agents/user-auth-interrupts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,21 @@ This automatically returns authorization URLs instead of throwing errors.
```javascript
import { isAuthorizationRequiredError } from "@arcadeai/arcadejs/lib";

const tools = arcadeTools.map(({ name, description, execute, parameters }) =>
tool({
name,
description: description ?? "",
parameters: parameters as any,
execute,
errorFunction: async(_, error) => {
if (error instanceof Error && isAuthorizationRequiredError(error)) {
const response = await client.tools.authorize({
tool_name: name,
user_id: "<YOUR_SYSTEM_USER_ID_2>",
});
return `Please login to Google: ${response.url}`;
}
return "Error executing tool"
}
}),
);
const tools = arcadeTools.map((arcadeTool) => {
return tool({
...arcadeTool,
errorFunction: async (_, error) => {
if (error instanceof Error && isAuthorizationRequiredError(error)) {
const response = await client.tools.authorize({
tool_name: arcadeTool.name,
user_id: "<YOUR_SYSTEM_USER_ID>",
});
return `Please login to Google: ${response.url}`;
}
return "Error executing tool"
}
})
});
```
</Tabs.Tab>

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


```javascript
const tools = arcadeTools.map(({ name, description, execute, parameters }) =>
tool({
name,
description: description ?? "",
parameters: parameters as any,
execute,
errorFunction: (_, error) => { throw error } // Throw the error to the agent for handling
}),
);
const tools = arcadeTools.map((arcadeTool) => {
return tool({
...arcadeTool,
errorFunction: (_, error) => { throw error } // Throw the error to the agent for handling
})
});

while (true) {
try {
Expand Down Expand Up @@ -374,31 +368,21 @@ async function main() {

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

// 3) Convert the tools to a format that OpenAI Agents can use
const tools = arcadeTools.map(({ name, description, execute, parameters }) =>
tool({
name,
description: description ?? "",
parameters: parameters as any,
execute,
errorFunction: (_, error) => { throw error }
}),
);

// 4) Create a new agent with the Google toolkit
// 3) Create a new agent with the Google toolkit
const googleAgent = new Agent({
name: "Google agent",
instructions: "You are a helpful assistant that can assist with Google API calls.",
model: "gpt-4o-mini",
tools
});

// 4) Run the agent, if authorization is required, wait for it to complete and retry
while (true) {
try {
const result = await run(googleAgent, "What are my latest emails?");
Expand All @@ -413,7 +397,7 @@ async function main() {
if (response.status !== "completed") {
console.log(`Please complete the authorization challenge in your browser: ${response.url}`);
}

// Wait for the authorization to complete
await client.auth.waitForCompletion(response);
console.log("Authorization completed, retrying...");
Expand Down