> 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/tools-and-mcp/python.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# Python

Package: `dnotifier`

## Setup

```python
import os
from dnotifier import DNotifier

notifier = DNotifier(
    app_id=os.environ["DNOTIFIER_APP_ID"],
    secret=os.environ["DNOTIFIER_SECRET"],
    transport="http",
    user_id="user-123",
    permission_enforcement="backend",  # or "disabled"
    on_agent_event=lambda event: print(event.get("type"), event.get("toolId")),
)

await notifier.connect()
```

## Register a local tool

```python
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",
        "inputSchema": {
            "type": "object",
            "properties": {
                "a": {"type": "number"},
                "b": {"type": "number"},
            },
            "required": ["a", "b"],
        },
        "execute": add_numbers,
    }
)
```

`execute` must be awaitable (use `async def`).

## Connect MCP

```python
mermaid = await notifier.mcp.connect(
    {
        "id": "mermaid",
        "name": "Agentic Mermaid",
        "transport": "http",
        "endpoint": "https://agentic-mermaid.dev/mcp",
    }
)

tools = mermaid.tools()
verify = next(t for t in tools if t["name"] == "mermaid.verify")

direct = await verify["execute"](
    {"source": "flowchart LR\n  A --> B"},
    {"executionId": "manual", "agentId": "manual", "toolId": verify["id"]},
)
```

## Define a tool agent

```python
from dnotifier import define_agent

agent = define_agent(
    name="math-assistant",
    description="Does arithmetic with tools",
    instructions="Use math.add when the user asks to add numbers. Be concise.",
    provider="open_ai",
    model="gpt-4o",
    observability=True,
    tools=[add],
    permissions={"math.add": ["execute"]},
)
```

Classic agents still use `define_agent(name, run=...)`. Tool agents may omit `run`.

## Run standalone

```python
result = await notifier.run_agent(
    agent,
    input="What is 21 + 21?",
    user_id="user-123",
    max_tool_rounds=6,
)

print(result["output"])
print(result["finishReason"])
print(result["executionId"])
```

## Inside a workflow

```python
from dnotifier import Workflow

workflow = Workflow(
    name="with-tools",
    observability=True,
    entry=lambda ctx: ctx.run_agent("math-assistant"),
).register_agents({"math-assistant": agent})

out = await notifier.run_workflow(workflow=workflow, input_data="Add 3 and 5")
print(out["result"])
```

## Errors

Import typed errors from `dnotifier` (for example `ToolNotFoundError`, `PermissionDeniedError`, `MCPConnectionError`, `LLMError`).

## Learn more

* [**Example: Local tool agent**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-tool-agent/python.md)
* [**Example: MCP Mermaid agent**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-mcp-agent/python.md)
* [**Define an agent**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/define-agent/python.md)
