> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-agui.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Team with Tool Hooks

This example demonstrates how to use tool hooks with teams and agents for intercepting and monitoring tool function calls, providing logging, timing, and other observability features.

## Code

```python team_with_tool_hooks.py theme={null}
import time
from typing import Any, Callable, Dict

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.team import Team
from agno.tools.hackernews import HackerNewsTools
from agno.tools.yfinance import YFinanceTools
from agno.utils.log import logger


def logger_hook(function_name: str, function_call: Callable, arguments: Dict[str, Any]):
    """
    Tool hook that logs function calls and measures execution time.

    Args:
        function_name: Name of the function being called
        function_call: The actual function to call
        arguments: Arguments passed to the function

    Returns:
        The result of the function call
    """
    if function_name == "delegate_task_to_member":
        member_id = arguments.get("member_id")
        logger.info(f"Delegating task to member {member_id}")

    # Start timer
    start_time = time.time()
    result = function_call(**arguments)
    # End timer
    end_time = time.time()
    duration = end_time - start_time
    logger.info(f"Function {function_name} took {duration:.2f} seconds to execute")
    return result


# News agent with tool hooks
news_agent = Agent(
    name="News Agent",
    id="news-agent",
    role="Search HackerNews for information",
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[HackerNewsTools(cache_results=True)],
    instructions=[
        "Find information about the company on HackerNews",
    ],
    tool_hooks=[logger_hook],
)

# Finance agent with tool hooks
finance_agent = Agent(
    name="Finance Agent",
    id="finance-agent",
    role="Get stock prices and financial data",
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[YFinanceTools(cache_results=True)],
    instructions=[
        "Get stock prices and financial information",
    ],
    tool_hooks=[logger_hook],
)

# Create team with tool hooks
research_team = Team(
    name="Research Team",
    model=OpenAIResponses(id="gpt-5.2"),
    members=[
        news_agent,
        finance_agent,
    ],
    markdown=True,
    instructions=[
        "You are a team that researches companies.",
        "Use the news agent for HackerNews discussions and finance agent for stock data.",
    ],
    show_members_responses=True,
    tool_hooks=[logger_hook],
)

if __name__ == "__main__":
    research_team.print_response(
        "Research NVIDIA - get the stock price and find any HackerNews discussions.",
        stream=True,
    )
```

## Usage

<Steps>
  <Step title="Create a Python file">
    Create `team_with_tool_hooks.py` with the code above.
  </Step>

  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno openai yfinance
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export OPENAI_API_KEY="your_openai_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run Team">
    ```bash theme={null}
    python team_with_tool_hooks.py
    ```
  </Step>
</Steps>
