> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-tool-agent/python.md).

# Python

```python
import asyncio
import os
from dnotifier import DNotifier, define_agent

async def main():
    notifier = DNotifier(
        app_id=os.environ["DNOTIFIER_APP_ID"],
        secret=os.environ["DNOTIFIER_SECRET"],
        transport="http",
        user_id="demo-user",
        permission_enforcement="disabled",  # use "backend" in production
        on_agent_event=lambda e: print("[agent]", e.get("type"), e.get("toolId")),
    )
    await notifier.connect()

    async def add_numbers(input_data, context):
        return {"sum": float(input_data["a"]) + float(input_data["b"])}

    add = notifier.tools.register(
        {
            "name": "math.add",
            "description": "Add two numbers and return { sum }",
            "inputSchema": {
                "type": "object",
                "properties": {
                    "a": {"type": "number"},
                    "b": {"type": "number"},
                },
                "required": ["a", "b"],
            },
            "execute": add_numbers,
        }
    )

    agent = define_agent(
        name="math-assistant",
        instructions=(
            "You are a calculator assistant. Use math.add for addition. Reply briefly."
        ),
        provider="open_ai",
        model="gpt-4o",
        observability=True,
        tools=[add],
        permissions={"math.add": ["execute"]},
    )

    result = await notifier.run_agent(
        agent,
        input="What is 21 + 21?",
        max_tool_rounds=4,
    )

    print("output:", result["output"])
    print("finishReason:", result["finishReason"])
    print("executionId:", result["executionId"])

if __name__ == "__main__":
    asyncio.run(main())
```

## Learn more

* [**Tools & MCP — Python**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/tools-and-mcp/python.md)
* [**MCP Mermaid example**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-mcp-agent/python.md)
