import asyncio, json, os, time

from agent_framework import Agent
from agent_framework.openai import OpenAIChatCompletionClient

CALLS = []


def get_weather(city: str) -> dict:
    """Return the current weather for a city."""
    CALLS.append(city)
    return {"city": city, "temp_c": 18, "condition": "cloudy"}


async def main():
    client = OpenAIChatCompletionClient(model=os.environ.get("MODEL", "qwen3.5:4b"),
                                        base_url="http://localhost:11434/v1", api_key="ollama")
    agent = Agent(client, instructions="Use the get_weather tool to answer weather questions.",
                  tools=[get_weather])
    t0 = time.time()
    result = await agent.run("What is the weather in Paris right now?")
    print(json.dumps({"calls": CALLS, "answer": result.text, "latency_s": round(time.time() - t0, 2)}))


asyncio.run(main())
