from pydantic_ai import Agentfrom pydantic_ai.models.instrumented import InstrumentationSettings# Create a PydanticAI agent with OTEL tracingagent = Agent( "openai:gpt-4o", instrument=InstrumentationSettings(tracer_provider=tracer_provider),)result = agent.run_sync("What is the capital of France?")print(result.output)
from pydantic_ai import Agentfrom pydantic_ai.models.instrumented import InstrumentationSettings# Create a PydanticAI agent with a system prompt and OTEL tracingagent = Agent( "openai:gpt-4o", system_prompt=( "You are a helpful assistant that can multiply numbers. " "When asked to multiply numbers, use the multiply tool." ), instrument=InstrumentationSettings(tracer_provider=tracer_provider),)# Define a tool@agent.tool_plaindef multiply(a: int, b: int) -> int: """Multiply two numbers.""" return a * b# Ask the agent to use the toolresult = agent.run_sync("What is 7 multiplied by 8?")print(result.output)
from pydantic_ai import Agentfrom pydantic_ai.models.instrumented import InstrumentationSettings# Set up default instrumentation for all agentsAgent.instrument_all(InstrumentationSettings(tracer_provider=tracer_provider))# Now, any new agent will use this instrumentation by defaultagent1 = Agent("openai:gpt-4o")agent2 = Agent("openai:gpt-4o", system_prompt="Be helpful.")result = agent1.run_sync("What is the capital of France?")print(result.output)