Skip to content

Commit 216eea2

Browse files
update agent usage detail (microsoft-foundry#502)
* update agent usage detail * add use agent in response --------- Co-authored-by: bobogogo1990 <[email protected]>
1 parent 29e7fb3 commit 216eea2

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

samples/typescript/quickstart/src/quickstart-chat-with-agent.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,45 @@ const deploymentName = process.env["MODEL_DEPLOYMENT_NAME"] || "<model deploymen
88
async function main(): Promise<void> {
99
const project = new AIProjectClient(projectEndpoint, new DefaultAzureCredential());
1010
const openAIClient = await project.getOpenAIClient();
11-
const response = await openAIClient.responses.create({
11+
12+
// Create agent
13+
console.log("Creating agent...");
14+
const agent = await project.agents.createVersion("my-agent-basic", {
15+
kind: "prompt",
1216
model: deploymentName,
13-
input: "What is the size of France in square miles?",
17+
instructions: "You are a helpful assistant that answers general questions",
1418
});
15-
const response2 = await openAIClient.responses.create({
16-
model: deploymentName,
17-
input: "And what is the capital city?",
18-
previous_response_id: response.id,
19+
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
20+
21+
// Create conversation with initial user message
22+
// You can save the conversation ID to database to retrieve later
23+
console.log("\nCreating conversation with initial user message...");
24+
const conversation = await openAIClient.conversations.create({
25+
items: [
26+
{ type: "message", role: "user", content: "What is the size of France in square miles?" },
27+
],
1928
});
20-
console.log(`Response output: ${response2.output_text}`);
21-
};
29+
console.log(`Created conversation with initial user message (id: ${conversation.id})`);
30+
31+
// Generate response using the agent
32+
console.log("\nGenerating response...");
33+
const response = await openAIClient.responses.create(
34+
{
35+
conversation: conversation.id,
36+
},
37+
{
38+
body: { agent: { name: agent.name, type: "agent_reference" } },
39+
},
40+
);
41+
console.log(`Response output: ${response.output_text}`);
42+
43+
// Clean up
44+
console.log("\nCleaning up resources...");
45+
await openAIClient.conversations.delete(conversation.id);
46+
console.log("Conversation deleted");
47+
48+
await project.agents.deleteVersion(agent.name, agent.version);
49+
console.log("Agent deleted");
50+
}
2251

2352
main().catch(console.error);

0 commit comments

Comments
 (0)