Files
agent-framework/python/samples/01-get-started/06_functional_workflow_basics.py
T
Evan Mattson 9b22ecd119 Python: Add requirements.txt and .env.example to the a2a/ sample for pip-based setup (#5510)
* Add requirements.txt and .env.example to a2a sample

Beginners following the a2a/ sample had no pip-based install path:
the directory lacked requirements.txt and .env.example, unlike every
other 04-hosting/ sample.

- Add requirements.txt with editable local package paths matching the
  pattern used in azure_functions/ and similar hosting samples
- Add .env.example documenting FOUNDRY_PROJECT_ENDPOINT, FOUNDRY_MODEL,
  and A2A_AGENT_HOST
- Update README Quick Start to cover both pip (.venv) and uv workflows

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Python: Add `requirements.txt` and `.env.example` to the `a2a/` sample for pip-based setup

Fixes #5395

* fix(a2a-sample): address PR review feedback for issue #5395

- Remove 'from repo root' wording from Option B uv heading in README
  to avoid contradicting the 'run from this directory' instruction
- Fix A2A_AGENT_HOST default in .env.example from 5001 to 5000 to match
  function-tools flow; add clarifying comments about port usage
- Add note for pip users explaining they can replace 'uv run python'
  with 'python' once the virtual environment is activated

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address review feedback for #5395: Python: [Samples][Python] a2a/ sample missing requirements.txt — beginners cannot install dependencies

---------

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-27 22:22:07 +00:00

60 lines
1.4 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
"""
Functional Workflow Basics — Orchestrate async functions with @workflow
The functional API lets you write workflows as plain Python async functions.
No graph concepts, no edges, no executor classes — just call functions
and use native control flow (if/else, loops, asyncio.gather).
This sample builds a minimal pipeline with two steps:
1. Convert text to uppercase
2. Reverse the text
No external services are required.
"""
import asyncio
from agent_framework import workflow
# Plain async functions — no decorators needed
async def to_upper_case(text: str) -> str:
"""Convert input to uppercase."""
return text.upper()
async def reverse_text(text: str) -> str:
"""Reverse the string."""
return text[::-1]
# <create_workflow>
@workflow
async def text_workflow(text: str) -> str:
"""Uppercase the text, then reverse it."""
upper = await to_upper_case(text)
return await reverse_text(upper)
# </create_workflow>
async def main() -> None:
# <run_workflow>
result = await text_workflow.run("hello world")
print(f"Output: {result.get_outputs()}")
print(f"Final state: {result.get_final_state()}")
# </run_workflow>
"""
Expected output:
Output: ['DLROW OLLEH']
Final state: WorkflowRunState.IDLE
"""
if __name__ == "__main__":
asyncio.run(main())