Python: Define Workflow and Executor APIs (#272)

* Workflow init commit

* Add samples and clean up

* ExecutionContext -> WorkflowContext

* Address comments 1

* Fix mypy

* flatting folder structure, and rename contexts

* Remove add_loop

* Add map reduce sample, remove Activation conditions

* Add AgentExecutor and allow multiple handlers per executor

* Minor improvement

* Add RequestInfoExecutor

* Add unit tests part 1

* Address comments 2

* Pre-commit update

* Add run method and more unit tests

* Add xml docs

* run_stream -> run_streaming

* message_handler -> handler

---------

Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
This commit is contained in:
Tao Chen
2025-08-06 16:26:15 -07:00
committed by GitHub
Unverified
parent 0d4d7abde1
commit c8694a8c76
34 changed files with 5036 additions and 431 deletions
@@ -0,0 +1,47 @@
# Copyright (c) Microsoft. All rights reserved.
import importlib
from typing import Any
PACKAGE_NAME = "agent_framework_workflow"
PACKAGE_EXTRA = "workflow"
_IMPORTS = [
"Executor",
"WorkflowContext",
"__version__",
"events",
"WorkflowBuilder",
"ExecutorCompletedEvent",
"ExecutorEvent",
"ExecutorInvokeEvent",
"RequestInfoEvent",
"WorkflowCompletedEvent",
"WorkflowEvent",
"WorkflowStartedEvent",
"AgentRunEvent",
"AgentRunStreamingEvent",
"handler",
"AgentExecutor",
"AgentExecutorRequest",
"AgentExecutorResponse",
"RequestInfoExecutor",
"RequestInfoMessage",
"WorkflowRunResult",
"Workflow",
]
def __getattr__(name: str) -> Any:
if name in _IMPORTS:
try:
return getattr(importlib.import_module(PACKAGE_NAME), name)
except ModuleNotFoundError as exc:
raise ModuleNotFoundError(
f"The '{PACKAGE_EXTRA}' extra is not installed, "
f"please do `pip install agent-framework[{PACKAGE_EXTRA}]`"
) from exc
raise AttributeError(f"Module {PACKAGE_NAME} has no attribute {name}.")
def __dir__() -> list[str]:
return _IMPORTS
@@ -0,0 +1,49 @@
# Copyright (c) Microsoft. All rights reserved.
from agent_framework_workflow import (
AgentExecutor,
AgentExecutorRequest,
AgentExecutorResponse,
AgentRunEvent,
AgentRunStreamingEvent,
Executor,
ExecutorCompletedEvent,
ExecutorEvent,
ExecutorInvokeEvent,
RequestInfoEvent,
RequestInfoExecutor,
RequestInfoMessage,
Workflow,
WorkflowBuilder,
WorkflowCompletedEvent,
WorkflowContext,
WorkflowEvent,
WorkflowRunResult,
WorkflowStartedEvent,
__version__,
handler,
)
__all__ = [
"AgentExecutor",
"AgentExecutorRequest",
"AgentExecutorResponse",
"AgentRunEvent",
"AgentRunStreamingEvent",
"Executor",
"ExecutorCompletedEvent",
"ExecutorEvent",
"ExecutorInvokeEvent",
"RequestInfoEvent",
"RequestInfoExecutor",
"RequestInfoMessage",
"Workflow",
"WorkflowBuilder",
"WorkflowCompletedEvent",
"WorkflowContext",
"WorkflowEvent",
"WorkflowRunResult",
"WorkflowStartedEvent",
"__version__",
"handler",
]