import json, os, time

from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider

CALLS = []
model = OpenAIChatModel(
    os.environ.get("MODEL", "qwen3.5:4b"),
    provider=OpenAIProvider(base_url="http://localhost:11434/v1", api_key="ollama"),
)
agent = Agent(model, instructions="Use the get_weather tool to answer weather questions.")


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


t0 = time.time()
result = agent.run_sync("What is the weather in Paris right now?")
print(json.dumps({"calls": CALLS, "answer": result.output, "latency_s": round(time.time() - t0, 2)}))
