Update OpenAI Agent example (#452)
Update with the latest `@arcadeai/arcadejs`
This commit is contained in:
parent
454390486a
commit
67bc53c8ce
4 changed files with 14 additions and 36 deletions
8
examples/openai-agents-ts/package-lock.json
generated
8
examples/openai-agents-ts/package-lock.json
generated
|
|
@ -9,14 +9,14 @@
|
|||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@arcadeai/arcadejs": "1.7.0",
|
||||
"@arcadeai/arcadejs": "1.8.1",
|
||||
"@openai/agents": "^0.0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/@arcadeai/arcadejs": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@arcadeai/arcadejs/-/arcadejs-1.7.0.tgz",
|
||||
"integrity": "sha512-Yw6/cUiywm/Ws/OCZvRGLJhmujDXYPmt6NW4DljkrBc/gceSJi/Yhjaum68cqsWXMqyeCM2Mg4PWkxOg8QJ8nA==",
|
||||
"version": "1.8.1",
|
||||
"resolved": "https://registry.npmjs.org/@arcadeai/arcadejs/-/arcadejs-1.8.1.tgz",
|
||||
"integrity": "sha512-ZTj2UvdfFmFn1as4gdDiZD8nbnEFZcZUzH9XtTmjRbgf/1V8s1wEtlzlI3vct+dA+KZ+NhS79AEw5lx/Ki0xSw==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@types/node": "^18.11.18",
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
"dev:waitForCompletion": "npx tsx --env-file=.env src/waitForCompletion.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@arcadeai/arcadejs": "1.7.0",
|
||||
"@arcadeai/arcadejs": "1.8.1",
|
||||
"@openai/agents": "^0.0.8"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,25 +7,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: "<YOUR_SYSTEM_USER_ID>", // Replace this with your application's user ID (e.g. email address, UUID, etc.)
|
||||
executeFactory: executeOrAuthorizeZodTool,
|
||||
})
|
||||
}).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,
|
||||
strict: true,
|
||||
}),
|
||||
);
|
||||
|
||||
// 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.",
|
||||
|
|
@ -33,8 +22,8 @@ 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);
|
||||
|
|
|
|||
|
|
@ -8,24 +8,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: "<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.",
|
||||
|
|
@ -33,7 +22,7 @@ async function main() {
|
|||
tools
|
||||
});
|
||||
|
||||
// 5) Run the agent, if authorization is required, wait for it to complete and retry
|
||||
// 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?");
|
||||
|
|
|
|||
Loading…
Reference in a new issue