agent.py
· 892 B · Python
Raw
import asyncio
from agents import Agent, Runner, ModelSettings
from agents.tracing import trace
from dotenv import load_dotenv
load_dotenv()
browser = Agent(
name="Browser",
model="computer-use-preview-2025-03-11",
model_settings=ModelSettings(truncation="auto"),
instructions="You can do tasks like searching the web, running code, and more.",
)
search = Agent(
name="Search",
model="gpt-4o-search-preview-2025-03-11",
instructions="You can search the web for information.",
)
agent = Agent(
name="Smith",
model="gpt-4o-mini",
instructions="You are a helpful assistant",
handoffs=[browser, search],
)
async def main():
prompt = input("Enter a prompt: ")
with trace(workflow_name="agent_smith"):
result = await Runner.run(agent, prompt)
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())
| 1 | import asyncio |
| 2 | from agents import Agent, Runner, ModelSettings |
| 3 | from agents.tracing import trace |
| 4 | from dotenv import load_dotenv |
| 5 | |
| 6 | load_dotenv() |
| 7 | |
| 8 | |
| 9 | browser = Agent( |
| 10 | name="Browser", |
| 11 | model="computer-use-preview-2025-03-11", |
| 12 | model_settings=ModelSettings(truncation="auto"), |
| 13 | instructions="You can do tasks like searching the web, running code, and more.", |
| 14 | ) |
| 15 | |
| 16 | search = Agent( |
| 17 | name="Search", |
| 18 | model="gpt-4o-search-preview-2025-03-11", |
| 19 | instructions="You can search the web for information.", |
| 20 | ) |
| 21 | |
| 22 | agent = Agent( |
| 23 | name="Smith", |
| 24 | model="gpt-4o-mini", |
| 25 | instructions="You are a helpful assistant", |
| 26 | handoffs=[browser, search], |
| 27 | ) |
| 28 | |
| 29 | |
| 30 | async def main(): |
| 31 | prompt = input("Enter a prompt: ") |
| 32 | with trace(workflow_name="agent_smith"): |
| 33 | result = await Runner.run(agent, prompt) |
| 34 | print(result.final_output) |
| 35 | |
| 36 | |
| 37 | if __name__ == "__main__": |
| 38 | asyncio.run(main()) |
| 39 |