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

# Add Tool After Initialization

> Attach a new tool to an existing agent at runtime with add_tool().

```python add_tool_after_initialization.py theme={null}
"""
Add Tool After Initialization
=============================

Demonstrates add tool after initialization.
"""

import random

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools import tool

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


@tool(stop_after_tool_call=True)
def get_weather(city: str) -> str:
    """Get the weather for a city."""
    # In a real implementation, this would call a weather API
    weather_conditions = ["sunny", "cloudy", "rainy", "snowy", "windy"]
    random_weather = random.choice(weather_conditions)

    return f"The weather in {city} is {random_weather}."


agent = Agent(
    model=OpenAIChat(id="gpt-5.2"),
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response("What can you do?", stream=True)

    agent.add_tool(get_weather)

    agent.print_response("What is the weather in San Francisco?", stream=True)
```

## Run the Example

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno openai
    ```
  </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 the example">
    Save the code above as `add_tool_after_initialization.py`, then run:

    ```bash theme={null}
    python add_tool_after_initialization.py
    ```
  </Step>
</Steps>

Full source: [cookbook/91\_tools/other/add\_tool\_after\_initialization.py](https://github.com/agno-agi/agno/blob/main/cookbook/91_tools/other/add_tool_after_initialization.py)
