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

# Python

Compose agents into a **workflow** with an `entry` function and `register_agents`.

## Intent router workflow

```python
from dnotifier import Workflow

async def intent_router_entry(ctx):
    intent_result = await ctx.run_agent("intent-agent")
    intent = (intent_result.get("intent") if isinstance(intent_result, dict) else None) or "general"
    ctx.state["intent"] = intent

    if intent == "search":
        input_data = ctx.input
        if isinstance(input_data, str):
            query = input_data
        elif isinstance(input_data, dict):
            query = str(input_data.get("query") or input_data.get("text") or "")
        else:
            query = str(input_data)

        hits = await ctx.search(
            query=query,
            limit=10,
            min_similarity=0.3,
            filterby_source="help-center",
            label="Semantic search",
        )
        ctx.state["search_results"] = hits
        return {"branch": "search", "intent": intent_result, "hits": hits}

    enriched_input = {
        "question": ctx.input if isinstance(ctx.input, str) else ctx.input,
        "intent_meta": intent_result,
    }
    general_result = await ctx.run_agent("general-agent", input_data=enriched_input)

    return {"branch": "general", "intent": intent_result, "answer": general_result}

intent_router_workflow = Workflow(
    name="support-intent-router",
    description="Classify intent then search or general chat",
    observability=True,
    entry=intent_router_entry,
).register_agents({
    "intent-agent": intent_agent,
    "general-agent": general_agent,
})
```

## Blog pipeline workflow (sequential)

```python
async def blog_article_entry(ctx):
    brief = ctx.input
    ctx.state["blog_brief"] = brief

    creation = await ctx.run_agent("content-creator")
    ctx.state["stage"] = "content_creation"

    clarity = await ctx.run_agent(
        "clarity-editor",
        input_data={"content": creation.get("content") if isinstance(creation, dict) else None},
    )
    ctx.state["stage"] = "clarity"

    seo = await ctx.run_agent(
        "seo-optimizer",
        input_data={
            "content": clarity.get("content") if isinstance(clarity, dict) else None,
            "topic": brief.get("topic") if isinstance(brief, dict) else None,
            "keywords": brief.get("keywords") if isinstance(brief, dict) else None,
        },
    )
    ctx.state["stage"] = "seo"

    return {
        "article": seo.get("content") if isinstance(seo, dict) else None,
        "seo": {
            "metaTitle": seo.get("metaTitle") if isinstance(seo, dict) else None,
            "metaDescription": seo.get("metaDescription") if isinstance(seo, dict) else None,
            "slug": seo.get("slug") if isinstance(seo, dict) else None,
            "keywords": seo.get("keywords") if isinstance(seo, dict) else None,
        },
    }

blog_article_workflow = Workflow(
    name="blog-article-writer",
    description="Create, refine, and optimize a blog post",
    observability=True,
    entry=blog_article_entry,
).register_agents({
    "content-creator": content_creator_agent,
    "clarity-editor": clarity_editor_agent,
    "seo-optimizer": seo_optimizer_agent,
})
```

## Parallel pipeline (`run_agents`)

```python
async def blog_article_parallel_entry(ctx):
    brief = ctx.input
    ctx.state["blog_brief"] = brief

    planning = await ctx.run_agents([
        {"name": "outline-planner"},
        {"name": "keyword-researcher"},
    ])
    outline_plan, keyword_research = planning["results"]

    creation = await ctx.run_agent(
        "content-creator",
        input_data={
            **(brief if isinstance(brief, dict) else {}),
            "outline": outline_plan.get("outline"),
            "keywords": keyword_research.get("keywords"),
        },
    )

    refinement = await ctx.run_agents([
        {"name": "clarity-editor", "input": {"content": creation.get("content")}},
        {
            "name": "seo-optimizer",
            "input": {
                "content": creation.get("content"),
                "topic": brief.get("topic") if isinstance(brief, dict) else None,
            },
        },
    ])
    clarity, seo = refinement["results"]
    return {"article": clarity.get("content"), "seo": seo}
```

See [**Parallel agents & shared state**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/step-graph.md) for more patterns.

## Learn more

* [**Parallel agents & shared state**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/step-graph.md)
* [**Run a workflow**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/run-workflow/python.md)
* [**Example: Multi-agent pipeline**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-multi-agent/python.md)
