-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy path33-single-turn-tool.ts
More file actions
64 lines (58 loc) · 1.91 KB
/
Copy path33-single-turn-tool.ts
File metadata and controls
64 lines (58 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* 33 - Single-Turn Tool Call
*
* The simplest tool-calling pattern: the user asks a question, the LLM
* calls a tool to get data, then responds with the answer. No iterative
* loop -- the agent runs for exactly one exchange.
*
* Compiled workflow:
* LLM(prompt, tools) -> tool executes -> LLM sees result -> answer
*
* Requirements:
* - Conductor server with LLM support
* - AGENTSPAN_SERVER_URL=http://localhost:8080/api as environment variable
* - AGENTSPAN_LLM_MODEL=openai/gpt-4o-mini as environment variable
*/
import { Agent, AgentRuntime, tool } from '@io-orkes/conductor-javascript/agents';
import { llmModel } from './settings';
const getWeather = tool(
async (args: { city: string }) => {
return { city: args.city, temp_f: 72, condition: 'Sunny' };
},
{
name: 'get_weather',
description: 'Get the current weather for a city.',
inputSchema: {
type: 'object',
properties: {
city: { type: 'string', description: 'City name' },
},
required: ['city'],
},
},
);
export const agent = new Agent({
name: 'weather_agent',
model: llmModel,
instructions: 'You are a weather assistant. Use the get_weather tool to answer.',
tools: [getWeather],
maxTurns: 2, // 1 turn to call the tool, 1 turn to answer
});
async function main() {
const runtime = new AgentRuntime();
try {
const result = await runtime.run(agent, "What's the weather in San Francisco?");
result.printResult();
// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(agent);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents weather_agent
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(agent);
} finally {
await runtime.shutdown();
}
}
main().catch(console.error);