Python: [BREAKING] Move workflow to main package (#767)

* Move workflow to main package

* Remove workflow specific unit test config

* Remove workflow-specific version info

* Revert unintended telemetry changes

* Removed the obsolete packages/workflow/tests target

* Rename dir workflow to _workflow

* Fix test imports
This commit is contained in:
Evan Mattson
2025-09-16 21:04:07 +09:00
committed by GitHub
Unverified
parent 65dd48aa1d
commit 732d9f6cd7
87 changed files with 524 additions and 595 deletions
@@ -3,14 +3,14 @@
import asyncio
from typing import Any
from agent_framework.telemetry import setup_telemetry
from agent_framework.workflow import (
from agent_framework import (
Executor,
WorkflowBuilder,
WorkflowCompletedEvent,
WorkflowContext,
handler,
)
from agent_framework.telemetry import setup_telemetry
from opentelemetry import trace
from opentelemetry.trace import SpanKind
from opentelemetry.trace.span import format_trace_id
@@ -2,16 +2,12 @@
## Installation
To install the base `agent_framework.workflow` package, run:
```bash
pip install agent-framework-workflow
```
Workflow support ships with the core `agent-framework` package, so no extra installation step is required.
To install with visualization support:
```bash
pip install agent-framework-workflow[viz]
pip install agent-framework[viz]
```
To export visualization images you also need to [install GraphViz](https://graphviz.org/download/).
@@ -2,7 +2,7 @@
import asyncio
from agent_framework.workflow import (
from agent_framework import (
Executor,
WorkflowBuilder,
WorkflowCompletedEvent,
@@ -2,8 +2,8 @@
import asyncio
from agent_framework import AgentRunEvent, WorkflowBuilder
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import AgentRunEvent, WorkflowBuilder
from azure.identity import AzureCliCredential
"""
@@ -2,9 +2,9 @@
import asyncio
from agent_framework import ChatAgent, ChatMessage
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import (
from agent_framework import (
ChatAgent,
ChatMessage,
Executor,
ExecutorFailedEvent,
WorkflowBuilder,
@@ -15,6 +15,7 @@ from agent_framework.workflow import (
WorkflowStatusEvent,
handler,
)
from agent_framework.azure import AzureChatClient
from azure.identity import AzureCliCredential
"""
@@ -2,8 +2,8 @@
import asyncio
from agent_framework import AgentRunUpdateEvent, WorkflowBuilder, WorkflowCompletedEvent
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import AgentRunUpdateEvent, WorkflowBuilder, WorkflowCompletedEvent
from azure.identity import AzureCliCredential
"""
@@ -2,9 +2,16 @@
import asyncio
from agent_framework import ChatAgent, ChatMessage
from agent_framework import (
ChatAgent,
ChatMessage,
Executor,
WorkflowBuilder,
WorkflowCompletedEvent,
WorkflowContext,
handler,
)
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import Executor, WorkflowBuilder, WorkflowCompletedEvent, WorkflowContext, handler
from azure.identity import AzureCliCredential
"""
@@ -3,7 +3,7 @@
# import asyncio
# from agent_framework.foundry import FoundryChatClient
# from agent_framework.workflow import AgentRunUpdateEvent, WorkflowBuilder, WorkflowCompletedEvent
# from agent_framework import AgentRunUpdateEvent, WorkflowBuilder, WorkflowCompletedEvent
# from azure.identity.aio import AzureCliCredential
# """
@@ -100,7 +100,7 @@ from typing import Any
from collections.abc import Awaitable, Callable
from agent_framework.foundry import FoundryChatClient
from agent_framework.workflow import AgentRunUpdateEvent, WorkflowBuilder, WorkflowCompletedEvent
from agent_framework import AgentRunUpdateEvent, WorkflowBuilder, WorkflowCompletedEvent
from azure.identity.aio import AzureCliCredential
@@ -10,7 +10,7 @@ from agent_framework import (
Role,
)
from agent_framework.openai import OpenAIChatClient
from agent_framework.workflow import (
from agent_framework import (
Executor,
RequestInfoExecutor,
RequestInfoMessage,
@@ -6,7 +6,7 @@ from uuid import uuid4
from agent_framework import AgentRunResponseUpdate, ChatClientProtocol, ChatMessage, Contents, Role
from agent_framework.openai import OpenAIChatClient
from agent_framework.workflow import AgentRunUpdateEvent, Executor, WorkflowBuilder, WorkflowContext, handler
from agent_framework import AgentRunUpdateEvent, Executor, WorkflowBuilder, WorkflowContext, handler
from pydantic import BaseModel
"""
@@ -5,19 +5,20 @@ import os
from pathlib import Path
from typing import Any
from agent_framework import ChatMessage, Role
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import (
from agent_framework import (
AgentExecutor,
AgentExecutorRequest,
AgentExecutorResponse,
ChatMessage,
Executor,
FileCheckpointStorage,
Role,
WorkflowBuilder,
WorkflowCompletedEvent,
WorkflowContext,
handler,
)
from agent_framework.azure import AzureChatClient
from azure.identity import AzureCliCredential
"""
@@ -4,7 +4,7 @@ import asyncio
from dataclasses import dataclass
from typing import Any
from agent_framework.workflow import (
from agent_framework import (
Executor,
WorkflowBuilder,
WorkflowCompletedEvent,
@@ -4,7 +4,7 @@ import asyncio
from dataclasses import dataclass
from typing import Any
from agent_framework.workflow import (
from agent_framework import (
Executor,
RequestInfoExecutor,
WorkflowBuilder,
@@ -15,7 +15,7 @@ from agent_framework.workflow import (
# Import the new sub-workflow types directly from the implementation package
try:
from agent_framework_workflow import (
from agent_framework import (
RequestInfoMessage,
RequestResponse,
WorkflowExecutor,
@@ -26,7 +26,7 @@ except ImportError:
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "packages", "workflow"))
from agent_framework_workflow import (
from agent_framework import (
RequestInfoMessage,
RequestResponse,
WorkflowExecutor,
@@ -4,7 +4,7 @@ import asyncio
from dataclasses import dataclass
from typing import Any
from agent_framework_workflow import (
from agent_framework import (
Executor,
RequestInfoExecutor,
RequestInfoMessage,
@@ -4,17 +4,18 @@ import asyncio
import os
from typing import Any
from agent_framework import ChatMessage, Role # Core chat primitives used to build requests
from agent_framework.azure import AzureChatClient # Thin client wrapper for Azure OpenAI chat models
from agent_framework.workflow import (
from agent_framework import ( # Core chat primitives used to build requests
AgentExecutor, # Wraps an LLM agent that can be invoked inside a workflow
AgentExecutorRequest, # Input message bundle for an AgentExecutor
AgentExecutorResponse, # Output from an AgentExecutor
ChatMessage,
Role,
WorkflowBuilder, # Fluent builder for wiring executors and edges
WorkflowCompletedEvent, # Event we emit at the end to signal completion
WorkflowContext, # Per-run context and event bus
executor, # Decorator to declare a Python function as a workflow executor
)
from agent_framework.azure import AzureChatClient # Thin client wrapper for Azure OpenAI chat models
from azure.identity import AzureCliCredential # Uses your az CLI login for credentials
from pydantic import BaseModel # Structured outputs for safer parsing
@@ -8,18 +8,19 @@ from dataclasses import dataclass
from typing import Literal
from uuid import uuid4
from agent_framework import ChatMessage, Role
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import (
from agent_framework import (
AgentExecutor,
AgentExecutorRequest,
AgentExecutorResponse,
ChatMessage,
Role,
WorkflowBuilder,
WorkflowCompletedEvent,
WorkflowContext,
WorkflowEvent,
executor,
)
from agent_framework.azure import AzureChatClient
from azure.identity import AzureCliCredential
from pydantic import BaseModel
@@ -3,7 +3,7 @@
import asyncio
from typing import Any
from agent_framework.workflow import (
from agent_framework import (
Executor,
WorkflowBuilder,
WorkflowCompletedEvent,
@@ -2,7 +2,7 @@
import asyncio
from agent_framework.workflow import WorkflowBuilder, WorkflowCompletedEvent, WorkflowContext, executor
from agent_framework import WorkflowBuilder, WorkflowCompletedEvent, WorkflowContext, executor
"""
Sample: Foundational sequential workflow with streaming using function-style executors.
@@ -3,19 +3,20 @@
import asyncio
from enum import Enum
from agent_framework import ChatMessage, Role
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import (
from agent_framework import (
AgentExecutor,
AgentExecutorRequest,
AgentExecutorResponse,
ChatMessage,
Executor,
ExecutorCompletedEvent,
Role,
WorkflowBuilder,
WorkflowCompletedEvent,
WorkflowContext,
handler,
)
from agent_framework.azure import AzureChatClient
from azure.identity import AzureCliCredential
"""
@@ -6,19 +6,20 @@ from dataclasses import dataclass
from typing import Any, Literal
from uuid import uuid4
from agent_framework import ChatMessage, Role # Core chat primitives used to form LLM requests
from agent_framework.azure import AzureChatClient # Thin client for Azure OpenAI chat models
from agent_framework.workflow import (
from agent_framework import ( # Core chat primitives used to form LLM requests
AgentExecutor, # Wraps an agent so it can run inside a workflow
AgentExecutorRequest, # Message bundle sent to an AgentExecutor
AgentExecutorResponse, # Result returned by an AgentExecutor
Case, # Case entry for a switch-case edge group
ChatMessage,
Default, # Default branch when no cases match
Role,
WorkflowBuilder, # Fluent builder for assembling the graph
WorkflowCompletedEvent, # Terminal event for successful completion
WorkflowContext, # Per-run context and event bus
executor, # Decorator to turn a function into a workflow executor
)
from agent_framework.azure import AzureChatClient # Thin client for Azure OpenAI chat models
from azure.identity import AzureCliCredential # Uses your az CLI login for credentials
from pydantic import BaseModel # Structured outputs with validation
@@ -3,17 +3,17 @@
import asyncio
from dataclasses import dataclass
from agent_framework import ChatMessage, Role
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import (
from agent_framework import (
AgentExecutor, # Executor that runs the agent
AgentExecutorRequest, # Message bundle sent to an AgentExecutor
AgentExecutorResponse, # Result returned by an AgentExecutor
Executor,
ChatMessage, # Chat message structure
Executor, # Base class for workflow executors
RequestInfoEvent, # Event emitted when human input is requested
RequestInfoExecutor, # Special executor that collects human input out of band
RequestInfoMessage, # Base class for request payloads sent to RequestInfoExecutor
RequestResponse, # Correlates a human response with the original request
Role, # Enum of chat roles (user, assistant, system)
WorkflowBuilder, # Fluent builder for assembling the graph
WorkflowCompletedEvent, # Terminal event used to finish the workflow
WorkflowContext, # Per run context and event bus
@@ -21,6 +21,7 @@ from agent_framework.workflow import (
WorkflowStatusEvent, # Event emitted on run state changes
handler, # Decorator to expose an Executor method as a step
)
from agent_framework.azure import AzureChatClient
from azure.identity import AzureCliCredential
from pydantic import BaseModel
@@ -230,13 +231,11 @@ async def main() -> None:
# Detect run state transitions for a better developer experience.
pending_status = any(
isinstance(e, WorkflowStatusEvent)
and e.state == WorkflowRunState.IN_PROGRESS_PENDING_REQUESTS
isinstance(e, WorkflowStatusEvent) and e.state == WorkflowRunState.IN_PROGRESS_PENDING_REQUESTS
for e in events
)
idle_with_requests = any(
isinstance(e, WorkflowStatusEvent)
and e.state == WorkflowRunState.IDLE_WITH_PENDING_REQUESTS
isinstance(e, WorkflowStatusEvent) and e.state == WorkflowRunState.IDLE_WITH_PENDING_REQUESTS
for e in events
)
if pending_status:
@@ -4,7 +4,7 @@ import asyncio
import os
from typing import Any
from agent_framework_workflow import Executor, WorkflowBuilder, WorkflowContext, handler
from agent_framework import Executor, WorkflowBuilder, WorkflowContext, handler
"""Basic tracing workflow sample.
@@ -3,9 +3,8 @@
import asyncio
from typing import Any
from agent_framework import ChatMessage
from agent_framework import ChatMessage, ConcurrentBuilder, WorkflowCompletedEvent
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import ConcurrentBuilder, WorkflowCompletedEvent
from azure.identity import AzureCliCredential
"""
@@ -3,17 +3,18 @@
import asyncio
from typing import Any
from agent_framework import ChatAgent, ChatMessage
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import (
from agent_framework import (
AgentExecutorRequest,
AgentExecutorResponse,
ChatAgent,
ChatMessage,
ConcurrentBuilder,
Executor,
WorkflowCompletedEvent,
WorkflowContext,
handler,
)
from agent_framework.azure import AzureChatClient
from azure.identity import AzureCliCredential
"""
@@ -3,9 +3,8 @@
import asyncio
from typing import Any
from agent_framework import ChatMessage, Role
from agent_framework import ChatMessage, ConcurrentBuilder, Role, WorkflowCompletedEvent
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import ConcurrentBuilder, WorkflowCompletedEvent
from azure.identity import AzureCliCredential
"""
@@ -3,9 +3,9 @@
import asyncio
import logging
from agent_framework import ChatAgent, HostedCodeInterpreterTool
from agent_framework.openai import OpenAIChatClient, OpenAIResponsesClient
from agent_framework_workflow import (
from agent_framework import (
ChatAgent,
HostedCodeInterpreterTool,
MagenticAgentDeltaEvent,
MagenticAgentMessageEvent,
MagenticBuilder,
@@ -15,6 +15,7 @@ from agent_framework_workflow import (
MagenticOrchestratorMessageEvent,
WorkflowCompletedEvent,
)
from agent_framework.openai import OpenAIChatClient, OpenAIResponsesClient
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
@@ -4,9 +4,9 @@ import asyncio
import logging
from typing import cast
from agent_framework import ChatAgent, HostedCodeInterpreterTool
from agent_framework.openai import OpenAIChatClient, OpenAIResponsesClient
from agent_framework_workflow import (
from agent_framework import (
ChatAgent,
HostedCodeInterpreterTool,
MagenticAgentDeltaEvent,
MagenticAgentMessageEvent,
MagenticBuilder,
@@ -20,6 +20,7 @@ from agent_framework_workflow import (
RequestInfoEvent,
WorkflowCompletedEvent,
)
from agent_framework.openai import OpenAIChatClient, OpenAIResponsesClient
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
@@ -3,9 +3,8 @@
import asyncio
from typing import Any
from agent_framework import ChatMessage, Role
from agent_framework import ChatMessage, Role, SequentialBuilder, WorkflowCompletedEvent
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import SequentialBuilder, WorkflowCompletedEvent
from azure.identity import AzureCliCredential
"""
@@ -3,9 +3,16 @@
import asyncio
from typing import Any
from agent_framework import ChatMessage, Role
from agent_framework import (
ChatMessage,
Executor,
Role,
SequentialBuilder,
WorkflowCompletedEvent,
WorkflowContext,
handler,
)
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import Executor, SequentialBuilder, WorkflowCompletedEvent, WorkflowContext, handler
from azure.identity import AzureCliCredential
"""
@@ -4,19 +4,20 @@ import asyncio
from dataclasses import dataclass
from typing import Any
from agent_framework import ChatMessage, Role # Core chat primitives to build LLM requests
from agent_framework.azure import AzureChatClient # Client wrapper for Azure OpenAI chat models
from agent_framework.workflow import (
from agent_framework import ( # Core chat primitives to build LLM requests
AgentExecutor, # Wraps an LLM agent for use inside a workflow
AgentExecutorRequest, # The message bundle sent to an AgentExecutor
AgentExecutorResponse, # The structured result returned by an AgentExecutor
AgentRunEvent, # Tracing event for agent execution steps
ChatMessage, # Chat message structure
Executor, # Base class for custom Python executors
Role, # Enum of chat roles (user, assistant, system)
WorkflowBuilder, # Fluent builder for wiring the workflow graph
WorkflowCompletedEvent, # Terminal event carrying the final result
WorkflowContext, # Per run context and event bus
handler, # Decorator to mark an Executor method as invokable
)
from agent_framework.azure import AzureChatClient # Client wrapper for Azure OpenAI chat models
from azure.identity import AzureCliCredential # Uses your az CLI login for credentials
"""
@@ -8,7 +8,7 @@ from dataclasses import dataclass
from typing import Any
import aiofiles
from agent_framework.workflow import (
from agent_framework import (
Executor, # Base class for custom workflow steps
WorkflowBuilder, # Fluent graph builder for executors and edges
WorkflowCompletedEvent, # Terminal event that carries final output
@@ -296,7 +296,7 @@ async def main():
svg_file = viz.export(format="svg")
print(f"SVG file saved to: {svg_file}")
except ImportError:
print("Tip: Install 'viz' extra to export workflow visualization: pip install agent-framework-workflow[viz]")
print("Tip: Install 'viz' extra to export workflow visualization: pip install agent-framework[viz]")
# Step 3: Open the text file and read its content.
async with aiofiles.open(os.path.join(DIR, "resources", "long_text.txt"), "r") as f:
@@ -6,16 +6,17 @@ from dataclasses import dataclass
from typing import Any
from uuid import uuid4
from agent_framework import ChatMessage, Role
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import (
from agent_framework import (
AgentExecutorRequest,
AgentExecutorResponse,
ChatMessage,
Role,
WorkflowBuilder,
WorkflowCompletedEvent,
WorkflowContext,
executor,
)
from agent_framework.azure import AzureChatClient
from azure.identity import AzureCliCredential
from pydantic import BaseModel
@@ -4,20 +4,21 @@ import asyncio
from dataclasses import dataclass
from typing import Any
from agent_framework import ChatMessage, Role
from agent_framework.azure import AzureChatClient
from agent_framework.workflow import (
from agent_framework import (
AgentExecutor,
AgentExecutorRequest,
AgentExecutorResponse,
AgentRunEvent,
ChatMessage,
Executor,
Role,
WorkflowBuilder,
WorkflowCompletedEvent,
WorkflowContext,
WorkflowViz,
handler,
)
from agent_framework.azure import AzureChatClient
from azure.identity import AzureCliCredential
"""
@@ -31,7 +32,7 @@ What it does:
Prerequisites:
- Azure AI/ Azure OpenAI for `AzureChatClient` agents.
- Authentication via `azure-identity` — uses `AzureCliCredential()` (run `az login`).
- For visualization export: `pip install agent-framework-workflow[viz]` and install GraphViz binaries.
- For visualization export: `pip install agent-framework[viz]` and install GraphViz binaries.
"""
@@ -161,7 +162,7 @@ async def main() -> None:
svg_file = viz.export(format="svg")
print(f"SVG file saved to: {svg_file}")
except ImportError:
print("Tip: Install 'viz' extra to export workflow visualization: pip install agent-framework-workflow[viz]")
print("Tip: Install 'viz' extra to export workflow visualization: pip install agent-framework[viz]")
# 3) Run with a single prompt
completion: WorkflowCompletedEvent | None = None