fromddtrace.llmobsimportLLMObsfromddtrace.llmobs.typesimportPrompt# if your llm call is auto-instrumented...withLLMObs.annotation_context(prompt=Prompt(id="generate_answer_prompt",template="Generate an answer to this question :{user_question}. Only answer based on the information from this article : {article}",variables={"user_question":user_question,"article":article},rag_query_variables=["user_question"],rag_context_variables=["article"]),name="generate_answer"):oai_client.chat.completions.create(...)# autoinstrumented llm call# if your llm call is manually instrumented ...@llm(name="generate_answer")defgenerate_answer():...LLMObs.annotate(prompt=Prompt(id="generate_answer_prompt",template="Generate an answer to this question :{user_question}. Only answer based on the information from this article : {article}",variables={"user_question":user_question,"article":article},rag_query_variables=["user_question"],rag_context_variables=["article"]),)
fromddtrace.llmobsimportLLMObsfromagentsimportAgent,ModelSettings,function_tool@function_tooldefadd_numbers(a:int,b:int)->int:"""
Adds two numbers together.
"""returna+b@function_tooldefsubtract_numbers(a:int,b:int)->int:"""
Subtracts two numbers.
"""returna-b# List of tools available to the agent math_tutor_agent=Agent(name="Math Tutor",handoff_description="Specialist agent for math questions",instructions="You provide help with math problems. Please use the tools to find the answer.",model="o3-mini",tools=[add_numbers,subtract_numbers],)history_tutor_agent=Agent(name="History Tutor",handoff_description="Specialist agent for history questions",instructions="You provide help with history problems.",model="o3-mini",)# The triage agent decides which specialized agent to hand off the task to — another type of tool selection covered by this evaluation.triage_agent=Agent('openai:gpt-4o',model_settings=ModelSettings(temperature=0),instructions='What is the sum of 1 to 10?',handoffs=[math_tutor_agent,history_tutor_agent],)
importosfromddtrace.llmobsimportLLMObsfrompydantic_aiimportAgent# Define tools as regular functions with type hintsdefadd_numbers(a:int,b:int)->int:"""
Adds two numbers together.
"""returna+bdefsubtract_numbers(a:int,b:int)->int:"""
Subtracts two numbers.
"""returna-bdefmultiply_numbers(a:int,b:int)->int:"""
Multiplies two numbers.
"""returna*bdefdivide_numbers(a:int,b:int)->float:"""
Divides two numbers.
"""returna/b# Enable LLMObsLLMObs.enable(ml_app="tool_argument_correctness_test",api_key=os.environ["DD_API_KEY"],site=os.environ["DD_SITE"],agentless_enabled=True,)# Create the Math Tutor agent with toolsmath_tutor_agent=Agent('openai:gpt-5-nano',instructions="You provide help with math problems. Please use the tools to find the answer.",tools=[add_numbers,subtract_numbers,multiply_numbers,divide_numbers],)# Create the History Tutor agent (note: gpt-5-nano doesn't exist, using gpt-4o-mini)history_tutor_agent=Agent('openai:gpt-5-nano',instructions="You provide help with history problems.",)# Create the triage agent# Note: pydantic_ai handles handoffs differently - you'd typically use result_type # or custom logic to route between agentstriage_agent=Agent('openai:gpt-5-nano',instructions=('DO NOT RELY ON YOUR OWN MATHEMATICAL KNOWLEDGE, ''MAKE SURE TO CALL AVAILABLE TOOLS TO SOLVE EVERY SUBPROBLEM.'),tools=[add_numbers,subtract_numbers,multiply_numbers,divide_numbers],)# Run the agent synchronouslyresult=triage_agent.run_sync('''
Help me solve the following problem:
What is the sum of the numbers between 1 and 100?
Make sure you list out all the mathematical operations (addition, subtraction, multiplication, division) in order before you start calling tools in that order.
''')