Skip to content

Commit 9c23281

Browse files
fix: remove await from sync ctx.set_state() and fix Role enum usage
- ctx.set_state() and ctx.get_state() are synchronous in agent-framework 1.1.1 (return None/value directly). Removing incorrect await that caused: TypeError: object NoneType can't be used in 'await' expression - Role is a NewType (str alias) in 1.1.1, not an enum. Replace Role.USER and Role.ASSISTANT with string literals, and .role.value with .role - Replace removed TextContent with Content.from_text() in retry utils Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 369e3f7 commit 9c23281

10 files changed

Lines changed: 20 additions & 25 deletions

File tree

src/ContentProcessorWorkflow/src/libs/agent_framework/azure_openai_response_retry.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,14 @@ def _set_message_text(message: Any, new_text: str) -> Any:
242242
return out
243243

244244
# agent_framework Message: .text is read-only, but .contents is a
245-
# mutable list of content items (TextContent, DataContent, etc.).
246-
# Replace all text-type items with a single TextContent carrying the
247-
# truncated text.
245+
# mutable list of content items (Content objects).
246+
# Replace all items with a single Content carrying the truncated text.
248247
contents = getattr(message, "contents", None)
249248
if isinstance(contents, list):
250249
try:
251-
# Dynamically import TextContent to avoid a hard dependency on
252-
# a specific agent_framework version.
253-
from agent_framework._types import (
254-
TextContent, # type: ignore[import-untyped]
255-
)
250+
from agent_framework._types import Content
256251

257-
message.contents = [TextContent(text=new_text)]
252+
message.contents = [Content.from_text(new_text)]
258253
return message
259254
except Exception:
260255
# If import or mutation fails, try the generic path below.

src/ContentProcessorWorkflow/src/libs/agent_framework/groupchat_orchestrator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ def _backfill_tool_usage_from_conversation(
10421042
for msg in conversation:
10431043
try:
10441044
role = getattr(msg, "role", None)
1045-
if role != Role.ASSISTANT:
1045+
if role != "assistant":
10461046
continue
10471047

10481048
agent_name = getattr(msg, "author_name", None) or "assistant"

src/ContentProcessorWorkflow/src/libs/agent_framework/middlewares.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ async def process(
241241

242242
for i, message in enumerate(context.messages):
243243
content = message.text if message.text else str(message.contents)
244-
logger.debug(" Message %d (%s): %s", i + 1, message.role.value, content)
244+
logger.debug(" Message %d (%s): %s", i + 1, message.role, content)
245245

246246
logger.debug(
247247
"[InputObserverMiddleware] Total messages: %d", len(context.messages)
@@ -252,7 +252,7 @@ async def process(
252252
modified_count = 0
253253

254254
for message in context.messages:
255-
if message.role == Role.USER and message.text:
255+
if message.role == "user" and message.text:
256256
original_text = message.text
257257
updated_text = original_text
258258

src/ContentProcessorWorkflow/src/steps/document_process/executor/document_process_executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,5 +339,5 @@ async def _on_poll(poll_data: dict) -> None:
339339
)
340340
)
341341

342-
await ctx.set_state("workflow_output", workflow_output)
342+
ctx.set_state("workflow_output", workflow_output)
343343
await ctx.send_message(workflow_output)

src/ContentProcessorWorkflow/src/steps/gap_analysis/executor/gap_executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async def handle_execute(
142142
)
143143
)
144144

145-
await ctx.set_state("workflow_output", result)
145+
ctx.set_state("workflow_output", result)
146146
await ctx.yield_output(result)
147147
return
148148

@@ -205,7 +205,7 @@ async def handle_execute(
205205
Executor_Output(step_name="gap_analysis", output_data=gap_result)
206206
)
207207

208-
await ctx.set_state("workflow_output", result)
208+
ctx.set_state("workflow_output", result)
209209
await ctx.yield_output(result)
210210

211211
async def fetch_processed_result(self, process_id: str) -> dict | None:

src/ContentProcessorWorkflow/src/steps/rai/executor/rai_executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async def handle_exectue(
118118
Executor_Output(step_name="rai_analysis", output_data=rai_result)
119119
)
120120

121-
await ctx.set_state("workflow_output", result)
121+
ctx.set_state("workflow_output", result)
122122
await ctx.send_message(result)
123123
return
124124

src/ContentProcessorWorkflow/src/steps/summarize/executor/summarize_executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async def handle_execute(
123123
Executor_Output(step_name="summarizing", output_data=summarized_result)
124124
)
125125

126-
await ctx.set_state("workflow_output", result)
126+
ctx.set_state("workflow_output", result)
127127
await ctx.send_message(result)
128128
return
129129

@@ -204,7 +204,7 @@ async def handle_execute(
204204
Executor_Output(step_name="summarizing", output_data=summarized_result)
205205
)
206206

207-
await ctx.set_state("workflow_output", result)
207+
ctx.set_state("workflow_output", result)
208208
await ctx.send_message(result)
209209

210210
async def fetch_processed_steps_result(self, process_id: str) -> dict | None:

src/ContentProcessorWorkflow/tests/unit/libs/agent_framework/test_agent_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_build_delegates_to_chat_agent(self, mock_chat_agent):
8585
call_kwargs = mock_chat_agent.call_args
8686
assert call_kwargs.kwargs["name"] == "Bot"
8787
assert call_kwargs.kwargs["instructions"] == "Do stuff"
88-
assert call_kwargs.kwargs["temperature"] == 0.5
88+
assert call_kwargs.kwargs["default_options"]["temperature"] == 0.5
8989

9090

9191
# ── Static factory ───────────────────────────────────────────────────────────
@@ -107,7 +107,7 @@ def test_create_agent_delegates_to_chat_agent(self, mock_chat_agent):
107107
assert agent == "agent_instance"
108108
call_kwargs = mock_chat_agent.call_args
109109
assert call_kwargs.kwargs["name"] == "Bot"
110-
assert call_kwargs.kwargs["temperature"] == 0.3
110+
assert call_kwargs.kwargs["default_options"]["temperature"] == 0.3
111111

112112

113113
# ── with_kwargs ──────────────────────────────────────────────────────────────

src/ContentProcessorWorkflow/tests/unit/libs/agent_framework/test_azure_openai_response_retry_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88
from agent_framework import Message
9-
from agent_framework._types import TextContent
9+
from agent_framework._types import Content
1010

1111
from libs.agent_framework.azure_openai_response_retry import (
1212
ContextTrimConfig,
@@ -148,7 +148,7 @@ def test_message_replaces_contents(self) -> None:
148148
result = _set_message_text(m, "truncated")
149149
assert result.text == "truncated"
150150
assert len(result.contents) == 1
151-
assert isinstance(result.contents[0], TextContent)
151+
assert isinstance(result.contents[0], Content)
152152

153153

154154
class TestTrimMessagesWithMessage:

src/ContentProcessorWorkflow/tests/unit/libs/agent_framework/test_input_observer_middleware.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import asyncio
88
from types import SimpleNamespace
99

10-
from agent_framework import Message, Role
10+
from agent_framework import Message
1111

1212
from libs.agent_framework.middlewares import InputObserverMiddleware
1313

@@ -16,7 +16,7 @@ def test_input_observer_middleware_replaces_user_text_when_configured() -> None:
1616
async def _run() -> None:
1717
ctx = SimpleNamespace(
1818
messages=[
19-
Message(role=Role.USER, contents=["original"]),
19+
Message(role="user", contents=["original"]),
2020
]
2121
)
2222

@@ -27,7 +27,7 @@ async def _next(_context):
2727

2828
await mw.process(ctx, _next)
2929

30-
assert ctx.messages[0].role == Role.USER
30+
assert ctx.messages[0].role == "user"
3131
assert ctx.messages[0].text == "replacement"
3232

3333
asyncio.run(_run())

0 commit comments

Comments
 (0)