Created
March 12, 2025 10:26
Revisions
-
samuelcolvin created this gist
Mar 12, 2025 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ from typing_extensions import TypedDict import logfire from httpx import AsyncClient from agents import RunContextWrapper, Agent, function_tool, Runner from agents.tool import WebSearchTool logfire.configure() logfire.instrument_openai_agents() class Location(TypedDict): lat: float long: float @function_tool(failure_error_function=None) async def fetch_weather(ctx: RunContextWrapper[AsyncClient], location: Location) -> str: """Fetch the weather for a given location. Args: ctx: Run context object. location: The location to fetch the weather for. """ 1 / 0 return 'sunny' agent = Agent( name='weather agent', tools=[fetch_weather, WebSearchTool()] ) async def main(): async with AsyncClient() as client: logfire.instrument_httpx(client) result = await Runner.run(agent, "What's the weather link in London", context=client) print(result.final_output) if __name__ == '__main__': import asyncio asyncio.run(main())