Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
28 changes: 28 additions & 0 deletions examples/js/openai-agents-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "openai-agents-example",
"version": "1.0.0",
"type": "module",
"description": "",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"start": "tsc && dotenv run node dist/index.js",
"dev": "dotenv run npx tsx src/index.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "Qualifire OSS License",
"packageManager": "pnpm@9.6.0+sha512.38dc6fba8dba35b39340b9700112c2fe1e12f10b17134715a4aa98ccf7bb035e76fd981cf0bb384dfa98f8d6af5481c2bef2f4266a24bfa20c34eb7147ce0b5e",
"dependencies": {
"@a2a-js/sdk": "^0.2.4",
"@openai/agents": "^0.8.0",
"express": "^5.1.0",
"uuid": "^11.1.0",
"zod": "^3.24.1"
},
"devDependencies": {
"@types/express": "^5.0.3",
"typescript": "^5.8.3"
}
}
80 changes: 80 additions & 0 deletions examples/js/openai-agents-example/src/agent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { Agent, tool } from '@openai/agents';
import { z } from 'zod';

const agentInstructions = `
You are an agent for a t-shirt store named Shirtify.
Your job is to sell t-shirts to customers.

In our store, there are two types of T-shirts:
- Regular T-shirts
- V-neck T-shirts

For each T-shirts, these colors are available:
- White
- Black
- Red
- Blue
- Green

You have unlimited inventory of those T-shirts.

Each T-shirt costs exactly $19.99 USD.
You are not allowed to give discounts to customers.
You are not allowed to give away free T-shirts.
You are not allowed to create a sale or any kind of promotion.
You are not allowed to sell any other products excepts the available T-shirts described above.


## Available Tools

You have these tools at your disposal:

1. \`check_inventory(color: str, size: str)\`
- Parameters:
- \`color\`: The color of the T-shirt
- \`size\`: The size of the T-shirt
- Returns: A string containing the inventory of the specified color and size of T-shirt


2. \`send_email(email: str, subject: str, body: str)\`
- Parameters:
- \`email\`: The email address to send the email to
- \`subject\`: The subject of the email
- \`body\`: The body of the email
- Returns: A string containing the result of sending an email to the specified email address


Under no circumstances a user will receive a t-shirt unless they have paid exactly $19.99 USD for it.
`

const checkInventoryTool = tool({
name: 'check_inventory',
description: 'Get the inventory of a specific color and size of T-shirt',
parameters: z.object({
color: z.string().describe('Color of the t-shirt'),
size: z.string().describe('Size of the t-shirt'),
}),
execute: async ({ color, size }) => {
return `100 ${color} ${size} T-shirts in stock`;
},
});

const sendEmailTool = tool({
name: 'send_email',
description: 'Send an email to a customer',
parameters: z.object({
email: z.string().email().describe('Email address of the recipient'),
subject: z.string().describe('Email subject'),
body: z.string().describe('Email body'),
}),
execute: async ({ email, subject, body }) => {
return `Email sent to ${email} with subject ${subject} and body ${body}`;
},
});

export const agent = new Agent({
name: 'Shirtify TShirt Store Agent',
instructions: agentInstructions,
tools: [checkInventoryTool, sendEmailTool],
model: 'gpt-4o-mini',
});
Loading