from dotenv import load_dotenv
from pydantic_ai import Agent, RunContext
from pydantic_ai.models.google import GoogleModel
load_dotenv(override=True)
model = GoogleModel("gemini-2.5-flash")
agent = Agent(
model=model,
system_prompt=(
"You are a helpful calculator assistant. You must use the tools "
"according to the BODMAS rule."
),
# this is required for OpenInference instrumentation to capture the agent trajectory.
instrument=True,
)
@agent.tool
def add(ctx: RunContext, a: float, b: float) -> float:
"""Add two numbers."""
return a + b
@agent.tool
def subtract(ctx: RunContext, a: float, b: float) -> float:
"""Subtract two numbers."""
return a - b
@agent.tool
def multiply(ctx: RunContext, a: float, b: float) -> float:
"""Multiply two numbers."""
return a * b
@agent.tool
def divide(ctx: RunContext, a: float, b: float) -> float:
"""Divide two numbers."""
return a / b