Functional Workflow With Agents

Compose several agents into a pipeline with the gentlest workflow API: decorate an async function with @workflow and call agents inside it with plain await.

Part 5 of 72 Microsoft Agent Framework Python — Every Lesson

What this lesson demonstrates

So far, one agent per program. A workflow composes several. The functional workflow API is the softest entry point: ordinary Python control flow (if / for / await) is the orchestration. Here a WRITER agent drafts a paragraph and an EDITOR agent tightens it — two roles, one line of glue each.

The code

The @workflow-decorated function is the orchestration graph, written as normal async code:

@workflow
async def draft_and_edit(topic: str) -> str:
    draft = await writer.run(topic)
    print(f"\n[writer draft]\n{draft.text}\n")
    final = await editor.run(draft.text)
    return final.text

Run it and pull the return value out of the result:

result = await draft_and_edit.run("Deploying to production on a Friday")
print(result.get_outputs()[0])

What to notice

How it maps to Azure AI Foundry

Both agents share one FoundryChatClient, so the workflow makes two sequential Foundry Responses calls — writer, then editor. Construction is offline; only .run() touches the model. Same AzureCliCredential for auth.

Run it

uv run tutorial/01-get-started/05_functional_workflow_with_agents.py

Expected: a writer draft, then the editor’s tightened two-sentence version. Needs Foundry creds and az login.


Next: Functional Workflow Basics

Sources & References

The Python SDK this lesson exercises
Composing agents with the functional workflow API