Skip to content

Commit 8c6b12e

Browse files
authored
Python: DevUI, Fix message serialization issue, improve tests (#2674)
* fix message serialization issue, improve tests for devui * update tests
1 parent 2d3ba95 commit 8c6b12e

File tree

10 files changed

+1424
-366
lines changed

10 files changed

+1424
-366
lines changed

python/packages/devui/agent_framework_devui/_mapper.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,12 +918,16 @@ async def _convert_workflow_event(self, event: Any, context: dict[str, Any]) ->
918918

919919
# Create ExecutorActionItem with completed status
920920
# ExecutorCompletedEvent uses 'data' field, not 'result'
921+
# Serialize the result data to ensure it's JSON-serializable
922+
# (AgentExecutorResponse contains AgentRunResponse/ChatMessage which are SerializationMixin)
923+
raw_result = getattr(event, "data", None)
924+
serialized_result = self._serialize_value(raw_result) if raw_result is not None else None
921925
executor_item = ExecutorActionItem(
922926
type="executor_action",
923927
id=item_id,
924928
executor_id=executor_id,
925929
status="completed",
926-
result=getattr(event, "data", None),
930+
result=serialized_result,
927931
)
928932

929933
# Use our custom event type
@@ -939,15 +943,17 @@ async def _convert_workflow_event(self, event: Any, context: dict[str, Any]) ->
939943
if event_class == "ExecutorFailedEvent":
940944
executor_id = getattr(event, "executor_id", "unknown")
941945
item_id = context.get(f"exec_item_{executor_id}", f"exec_{executor_id}_unknown")
942-
error_info = getattr(event, "error", None)
946+
# ExecutorFailedEvent uses 'details' field (WorkflowErrorDetails), not 'error'
947+
details = getattr(event, "details", None)
948+
err_msg: str | None = str(getattr(details, "message", details)) if details else None
943949

944950
# Create ExecutorActionItem with failed status
945951
executor_item = ExecutorActionItem(
946952
type="executor_action",
947953
id=item_id,
948954
executor_id=executor_id,
949955
status="failed",
950-
error={"message": str(error_info)} if error_info else None,
956+
error={"message": err_msg} if err_msg else None,
951957
)
952958

953959
# Use our custom event type

python/packages/devui/agent_framework_devui/_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ async def _stream_execution(
11211121
yield "data: [DONE]\n\n"
11221122

11231123
except Exception as e:
1124-
logger.error(f"Error in streaming execution: {e}")
1124+
logger.error(f"Error in streaming execution: {e}", exc_info=True)
11251125
error_event = {"id": "error", "object": "error", "error": {"message": str(e), "type": "execution_error"}}
11261126
yield f"data: {json.dumps(error_event)}\n\n"
11271127

python/packages/devui/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ fallback-version = "0.0.0"
4949

5050
[tool.pytest.ini_options]
5151
testpaths = 'tests'
52+
pythonpath = ["tests"]
5253
addopts = "-ra -q -r fEX"
5354
asyncio_mode = "auto"
5455
asyncio_default_fixture_loop_scope = "function"

python/packages/devui/tests/__init__.py

Whitespace-only changes.

python/packages/devui/tests/test_cleanup_hooks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def __init__(self, name: str = "TestAgent"):
3636
async def run_stream(self, messages=None, *, thread=None, **kwargs):
3737
"""Mock streaming run method."""
3838
yield AgentRunResponse(
39-
messages=[ChatMessage(role=Role.ASSISTANT, content=[TextContent(text="Test response")])],
40-
inner_messages=[],
39+
messages=[ChatMessage(role=Role.ASSISTANT, contents=[TextContent(text="Test response")])],
4140
)
4241

4342

python/packages/devui/tests/test_discovery.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def test_entities_dir():
2121
return str(samples_dir.resolve())
2222

2323

24-
@pytest.mark.skip("Skipping while we fix discovery")
2524
async def test_discover_agents(test_entities_dir):
2625
"""Test that agent discovery works and returns valid agent entities."""
2726
discovery = EntityDiscovery(test_entities_dir)

0 commit comments

Comments
 (0)