[Python] Agno Agentic Framework - pydantic code ValidationError

Discussão em 'Python' iniciado por Stack, Março 28, 2025.

  1. Stack

    Stack Membro Participativo

    I was trying out the new agentic framework agno and wanted to test it out by writing a simple calculator.

    #main.py
    def add(x: int, y: int) -> int:
    """
    Use this function to add two numbers.
    Args:
    a (int): The first number.
    b (int): The second number.
    Returns:
    int: The sum of the two numbers.
    """
    print("Adding two numbers...")
    return x + y

    def subtract(x: int, y: int) -> int:
    """
    Use this function to subtract two numbers.
    Args:
    a (int): The first number.
    b (int): The second number.
    Returns:
    int: The difference of the two numbers.
    """
    print("Subtracting two numbers...")
    return x - y

    def multiply(x: int, y: int) -> int:
    """
    Use this function to multiply two numbers.
    Args:
    a (int): The first number.
    b (int): The second number.
    Returns:
    int: The product of the two numbers.
    """
    print("Multiplying two numbers...")
    return x * y

    def generate_random_number() -> int:
    """
    Use this function to generate a random number.
    Returns:
    int: A random number.
    """
    print("Generating a random number...")
    return 42

    def divide(x: int, y: int) -> float:
    """
    Use this function to divide two numbers.
    Args:
    a (int): The first number.
    b (int): The second number.
    Returns:
    float: The quotient of the two numbers.
    """
    print("Dividing two numbers...")
    return x / y

    calculator_agent = Agent(
    model=OpenRouter(id="google/gemini-2.0-flash-lite-preview-02-05:free"),
    name="Data Agent",
    description=dedent("""
    You are a helpful calulator agent. You can perform basic arithmetic operations like addition, subtraction, multiplication, and division with the help of the tools provided.
    """),
    instructions=[
    """Analyse the user query and use the tools to perform the required operation.""",
    ],
    tools=[add, subtract, multiply, divide, generate_random_number],
    show_tool_calls=True,
    debug_mode=True,
    add_history_to_messages=True,
    markdown=True,
    )

    response = calculator_agent.run("Add 2 to 5. Take the result and multiply it by 2. Take that output and divide it by a random number")
    print(response.content)


    The error I am getting is

    pydantic_core._pydantic_core.ValidationError: 2 validation errors for Message
    content.list[any]
    Input should be a valid list [type=list_type, input_value=7, input_type=int]
    For further information visit https://errors.pydantic.dev/2.11/v/list_type
    content.str
    Input should be a valid string [type=string_type, input_value=7, input_type=int]
    For further information visit https://errors.pydantic.dev/2.11/v/string_type


    But I am not stating anywhere that the result of the first addition needs to be a list neither for it to be a String.

    Can someone please tell me what I am doing wrong ? Should all custom tools only return types of string ?

    There was only one example at : https://docs.agno.com/agents/tools at it does seem to have str as the return type

    Continue reading...

Compartilhe esta Página