-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy path94_openai_runner_tools.py
More file actions
76 lines (54 loc) · 2.73 KB
/
Copy path94_openai_runner_tools.py
File metadata and controls
76 lines (54 loc) · 2.73 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
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright (c) 2025 Agentspan
# Licensed under the MIT License. See LICENSE file in the project root for details.
"""OpenAI Agents SDK migration — function tools.
This is examples/basic/tools.py from the openai-agents SDK
with exactly ONE line changed.
Before (runs directly against OpenAI):
from agents import Runner
After (runs on Agentspan — durable, observable, scalable):
from conductor.ai import Runner
The diff:
-from agents import Runner
+from conductor.ai import Runner
@function_tool decorators, Agent definition, and result.final_output
are completely unchanged. Agentspan executes each tool call as a durable
worker task — if the process crashes mid-run, execution resumes from the
last successful tool call.
Requirements:
- uv add openai-agents
- AGENTSPAN_SERVER_URL=http://localhost:8080/api
- AGENTSPAN_LLM_MODEL=openai/gpt-4o
Usage:
python 94_openai_runner_tools.py
"""
import asyncio
from typing import Annotated
from pydantic import BaseModel, Field
from agents import Agent, function_tool
# ── Only this line changes ──────────────────────────────────────────────────
# from agents import Runner # ← original (runs directly on OpenAI)
from conductor.ai import Runner # ← agentspan (runs on Agentspan)
# ───────────────────────────────────────────────────────────────────────────
class Weather(BaseModel):
city: str = Field(description="The city name")
temperature_range: str = Field(description="The temperature range in Celsius")
conditions: str = Field(description="The weather conditions")
# Keep the plain function importable at module level and apply
# @function_tool at Agent construction: worker processes are spawned on
# macOS/Windows and re-import this module by qualified name, which fails
# when the decorator has rebound the module global to a FunctionTool.
def get_weather(city: Annotated[str, "The city to get the weather for"]) -> Weather:
"""Get the current weather information for a specified city."""
print("[debug] get_weather called")
return Weather(city=city, temperature_range="14-20C", conditions="Sunny with wind.")
agent = Agent(
name="weather_agent",
instructions="You are a helpful agent.",
tools=[function_tool(get_weather)],
)
async def main():
result = await Runner.run(agent, input="What's the weather in Tokyo?")
print(result.final_output)
# The weather in Tokyo is sunny with a temperature range of 14-20°C.
if __name__ == "__main__":
asyncio.run(main())