This example demonstrates how to use a pre-hook to transform the input of an Team, before it is presented to the LLM.

Code

from typing import Optional

from agno.team import Team
from agno.models.openai import OpenAIChat
from agno.run.team import RunInput
from agno.session.team import TeamSession
from agno.utils.log import log_debug


def transform_input(
    run_input: RunInput,
    session: TeamSession,
    user_id: Optional[str] = None,
    debug_mode: Optional[bool] = None,
) -> None:
    """
    Pre-hook: Rewrite the input to be more relevant to the team's purpose.

    This hook rewrites the input to be more relevant to the team's purpose.
    """
    log_debug(
        f"Transforming input: {run_input.input_content} for user {user_id} and session {session.session_id}"
    )

    # Input transformation team
    transformer_team = Team(
        name="Input Transformer",
        model=OpenAIChat(id="gpt-5-mini"),
        instructions=[
            "You are an input transformation specialist.",
            "Rewrite the user request to be more relevant to the team's purpose.",
            "Use known context engineering standards to rewrite the input.",
            "Keep the input as concise as possible.",
            "The team's purpose is to provide investment guidance and financial planning advice.",
        ],
        debug_mode=debug_mode,
    )

    transformation_result = transformer_team.run(
        input=f"Transform this user request: '{run_input.input_content}'"
    )

    # Overwrite the input with the transformed input
    run_input.input_content = transformation_result.content
    log_debug(f"Transformed input: {run_input.input_content}")


print("🚀 Input Transformation Pre-Hook Example")
print("=" * 60)

# Create a financial advisor team with comprehensive hooks
team = Team(
    name="Financial Advisor",
    model=OpenAIChat(id="gpt-5-mini"),
    pre_hooks=[transform_input],
    description="A professional financial advisor providing investment guidance and financial planning advice.",
    instructions=[
        "You are a knowledgeable financial advisor with expertise in:",
        "• Investment strategies and portfolio management",
        "• Retirement planning and savings strategies",
        "• Risk assessment and diversification",
        "• Tax-efficient investing",
        "",
        "Provide clear, actionable advice while being mindful of individual circumstances.",
        "Always remind users to consult with a licensed financial advisor for personalized advice.",
    ],
    debug_mode=True,
)

team.print_response(
    input="I'm 35 years old and want to start investing for retirement. moderate risk tolerance. retirement savings in IRAs/401(k)s= $100,000. total savings is $200,000. my net worth is $300,000",
    session_id="test_session",
    user_id="test_user",
    stream=True,
)

Usage

1

Create a virtual environment

Open the Terminal and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
2

Install libraries

pip install -U agno openai
3

Run example

python cookbook/teams/hooks/input_transformation_pre_hook.py