From f3283876243043d4cf6c07d805f744b91100ec65 Mon Sep 17 00:00:00 2001 From: Teo Date: Fri, 1 Nov 2024 22:02:53 -0600 Subject: [PATCH 1/2] feat(orfix(orchestrator): OrchestratorError to serialize `Exception` as `str` --- src/controlflow/events/orchestrator_events.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/controlflow/events/orchestrator_events.py b/src/controlflow/events/orchestrator_events.py index 6c07fef1..932fe8de 100644 --- a/src/controlflow/events/orchestrator_events.py +++ b/src/controlflow/events/orchestrator_events.py @@ -1,4 +1,7 @@ -from typing import Literal +from dataclasses import Field +from typing import Annotated, Literal + +from pydantic.functional_serializers import PlainSerializer from controlflow.agents.agent import Agent from controlflow.events.base import UnpersistedEvent @@ -21,7 +24,7 @@ class OrchestratorError(UnpersistedEvent): event: Literal["orchestrator-error"] = "orchestrator-error" persist: bool = False orchestrator: Orchestrator - error: Exception + error: Annotated[Exception, PlainSerializer(lambda x: str(x), return_type=str)] class AgentTurnStart(UnpersistedEvent): From 92f6e24aa488ba25a3a579ce8f093e90e38fcf1d Mon Sep 17 00:00:00 2001 From: Teo Date: Sat, 2 Nov 2024 16:54:15 -0600 Subject: [PATCH 2/2] fix(agent.py): update handlers type annotation to support both Handler and AsyncHandler --- src/controlflow/agents/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controlflow/agents/agent.py b/src/controlflow/agents/agent.py index ef1be609..e14ee063 100644 --- a/src/controlflow/agents/agent.py +++ b/src/controlflow/agents/agent.py @@ -238,7 +238,7 @@ async def run_async( objective: str, *, turn_strategy: Optional["TurnStrategy"] = None, - handlers: Optional[list["Handler"]] = None, + handlers: Optional[list[Union["Handler", "AsyncHandler"]]] = None, **task_kwargs, ): return await controlflow.run_async(