diff --git a/pages/home/oai-agents/overview.mdx b/pages/home/oai-agents/overview.mdx index 7f29b0c6e..be2f88a67 100644 --- a/pages/home/oai-agents/overview.mdx +++ b/pages/home/oai-agents/overview.mdx @@ -103,25 +103,14 @@ 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: "", // 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.", @@ -129,10 +118,10 @@ const googleAgent = new Agent({ 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); ``` diff --git a/pages/home/oai-agents/use-arcade-tools.mdx b/pages/home/oai-agents/use-arcade-tools.mdx index e86a941c0..db97dec73 100644 --- a/pages/home/oai-agents/use-arcade-tools.mdx +++ b/pages/home/oai-agents/use-arcade-tools.mdx @@ -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: "", // 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 @@ -312,25 +302,14 @@ 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: "", // 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.", @@ -338,10 +317,10 @@ const googleAgent = new Agent({ 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); ``` diff --git a/pages/home/oai-agents/user-auth-interrupts.mdx b/pages/home/oai-agents/user-auth-interrupts.mdx index d05828391..512595e07 100644 --- a/pages/home/oai-agents/user-auth-interrupts.mdx +++ b/pages/home/oai-agents/user-auth-interrupts.mdx @@ -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: "", - }); - 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: "", + }); + return `Please login to Google: ${response.url}`; + } + return "Error executing tool" + } + }) +}); ``` @@ -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 { @@ -374,24 +368,13 @@ 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: "", // 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.", @@ -399,6 +382,7 @@ async function main() { 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?"); @@ -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...");