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

# Custom Tool Events

> Yield a custom CustomEvent subclass from an async @tool and consume it while streaming agent.arun().

Yield custom events from a custom tool and consume them while streaming.

> [!WARNING]
>
> This example omits `stream_events=True`, so Agno discards the yielded custom event. Add the option before running.

```python custom_tool_events.py theme={null}
"""This example demonstrate how to yield custom events from a custom tool."""

import asyncio
from dataclasses import dataclass
from typing import Optional

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

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


# Our custom event, extending the CustomEvent class
@dataclass
class CustomerProfileEvent(CustomEvent):
    """CustomEvent for customer profile."""

    customer_name: Optional[str] = None
    customer_email: Optional[str] = None
    customer_phone: Optional[str] = None


# Our custom tool
@tool()
async def get_customer_profile():
    """Example custom tool that simply yields a custom event."""

    yield CustomerProfileEvent(
        customer_name="John Doe",
        customer_email="john.doe@example.com",
        customer_phone="1234567890",
    )


# Setup an Agent with our custom tool.
agent = Agent(
    model=OpenAIChat(id="gpt-5.6-luna"),
    tools=[get_customer_profile],
    instructions="Your task is to retrieve customer profiles for the user.",
)


async def run_agent():
    # Running the Agent: it should call our custom tool and yield the custom event
    async for event in agent.arun(
        "Hello, can you get me the customer profile for customer with ID 123?",
        stream=True,
    ):
        if isinstance(event, CustomEvent):
            print(f"Custom event emitted: {event}")


# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    asyncio.run(run_agent())
```

## Run the Example

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

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno openai
```

**2. Export your OpenAI API key**

```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"
```

**3. Enable custom events**

In the saved file, add `stream_events=True` next to `stream=True` in the `agent.arun()` call.

**4. Run the example**

Save the code above as `custom_tool_events.py`, then run:

```bash theme={null}
python custom_tool_events.py
```

Full source: [cookbook/91\_tools/custom\_tool\_events.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/91_tools/custom_tool_events.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.