Skip to content

Commit 9fd159e

Browse files
Initial fix
1 parent 4c32c90 commit 9fd159e

File tree

8 files changed

+625
-325
lines changed

8 files changed

+625
-325
lines changed

examples/tutorials/10_agentic/10_temporal/000_hello_acp/project/workflow.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def __init__(self):
3333
@workflow.signal(name=SignalName.RECEIVE_EVENT)
3434
@override
3535
async def on_task_event_send(self, params: SendEventParams) -> None:
36-
logger.info(f"Received task message instruction: {params}")
3736

3837
# 2. Echo back the client's message to show it in the UI. This is not done by default so the agent developer has full control over what is shown to the user.
3938
await adk.messages.create(task_id=params.task.id, content=params.event.content)

examples/tutorials/10_agentic/10_temporal/010_agent_chat/dev.ipynb

Lines changed: 397 additions & 245 deletions
Large diffs are not rendered by default.

examples/tutorials/10_agentic/10_temporal/010_agent_chat/project/workflow.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ class StateModel(BaseModel):
4848
turn_number: int
4949

5050

51-
MCP_SERVERS = [
52-
StdioServerParameters(
53-
command="npx",
54-
args=["-y", "@modelcontextprotocol/server-sequential-thinking"],
55-
),
51+
MCP_SERVERS = [ # No longer needed due to reasoning
52+
# StdioServerParameters(
53+
# command="npx",
54+
# args=["-y", "@modelcontextprotocol/server-sequential-thinking"],
55+
# ),
5656
StdioServerParameters(
5757
command="uvx",
5858
args=["openai-websearch-mcp"],
@@ -163,7 +163,6 @@ def __init__(self):
163163
@workflow.signal(name=SignalName.RECEIVE_EVENT)
164164
@override
165165
async def on_task_event_send(self, params: SendEventParams) -> None:
166-
logger.info(f"Received task message instruction: {params}")
167166

168167
if not params.event.content:
169168
return

examples/tutorials/10_agentic/10_temporal/050_agent_chat_guardrails/project/workflow.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ def __init__(self):
387387
@workflow.signal(name=SignalName.RECEIVE_EVENT)
388388
@override
389389
async def on_task_event_send(self, params: SendEventParams) -> None:
390-
logger.info(f"Received task message instruction: {params}")
391390

392391
if not params.event.content:
393392
return

examples/tutorials/10_agentic/10_temporal/050_agent_chat_guardrails/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "An AgentEx agentthat streams multiturn tool-enabled chat with tra
99
readme = "README.md"
1010
requires-python = ">=3.12"
1111
dependencies = [
12-
"agentex-sdk",
12+
"agentex-sdk @ file://../../../../../",
1313
"debugpy>=1.8.15",
1414
"scale-gp",
1515
]
@@ -22,6 +22,9 @@ dev = [
2222
"flake8",
2323
]
2424

25+
[tool.hatch.metadata]
26+
allow-direct-references = true
27+
2528
[tool.hatch.build.targets.wheel]
2629
packages = ["project"]
2730

src/agentex/lib/core/services/adk/providers/openai.py

Lines changed: 158 additions & 62 deletions
Large diffs are not rendered by default.

src/agentex/lib/core/services/adk/streaming.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,35 @@ async def open(self) -> "StreamingTaskMessageContext":
208208

209209
return self
210210

211+
# Temp function to just send the full content
212+
async def send_full_content(self) -> TaskMessage:
213+
"""Send the full content message to the repository without updating the task message."""
214+
if not self.task_message:
215+
raise ValueError("Context not properly initialized - no task message")
216+
217+
if self._is_closed:
218+
return self.task_message # Already done
219+
220+
# Update the task message with the final content from accumulated deltas
221+
has_deltas = (
222+
self._delta_accumulator._accumulated_deltas or
223+
self._delta_accumulator._reasoning_summaries or
224+
self._delta_accumulator._reasoning_contents
225+
)
226+
if has_deltas:
227+
self.task_message.content = self._delta_accumulator.convert_to_content()
228+
229+
# Send the FULL event with the complete content
230+
full_event = StreamTaskMessageFull(
231+
parent_task_message=self.task_message,
232+
content=self.task_message.content,
233+
type="full",
234+
)
235+
await self._streaming_service.stream_update(full_event)
236+
237+
return self.task_message
238+
239+
211240
async def close(self) -> TaskMessage:
212241
"""Close the streaming context."""
213242
if not self.task_message:

src/agentex/lib/utils/dev_tools/async_messages.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def print_task_message(
5050

5151
# Skip empty reasoning messages
5252
if isinstance(message.content, ReasoningContent):
53-
has_summary = message.content.summary and any(s for s in message.content.summary if s)
54-
has_content = message.content.content and any(c for c in message.content.content if c)
53+
has_summary = bool(message.content.summary) and any(s for s in message.content.summary if s)
54+
has_content = bool(message.content.content) and any(c for c in message.content.content if c) if message.content.content is not None else False
5555
if not has_summary and not has_content:
5656
return
5757

@@ -136,18 +136,19 @@ def print_task_message(
136136

137137
if rich_print and console:
138138
author_color = "bright_cyan" if message.content.author == "user" else "green"
139-
title = f"[bold {author_color}]{message.content.author.upper()}[/bold {author_color}] [{timestamp}]"
140139

141-
# Use different border styles for tool messages
140+
# Use different border styles and colors for different content types
142141
if content_type == "tool_request":
143142
border_style = "yellow"
144143
elif content_type == "tool_response":
145144
border_style = "bright_green"
146145
elif content_type == "reasoning":
147146
border_style = "bright_magenta"
147+
author_color = "bright_magenta" # Also make the author text magenta
148148
else:
149149
border_style = author_color
150-
150+
151+
title = f"[bold {author_color}]{message.content.author.upper()}[/bold {author_color}] [{timestamp}]"
151152
panel = Panel(Markdown(content), title=title, border_style=border_style, width=80)
152153
console.print(panel)
153154
else:
@@ -330,6 +331,7 @@ def subscribe_to_async_task_messages(
330331

331332
# Deserialize the discriminated union TaskMessageUpdate based on the "type" field
332333
message_type = task_message_update_data.get("type", "unknown")
334+
333335

334336
# Handle different message types for streaming progress
335337
if message_type == "start":
@@ -360,11 +362,20 @@ def subscribe_to_async_task_messages(
360362
if index in active_spinners:
361363
active_spinners[index].stop()
362364
del active_spinners[index]
365+
# Ensure clean line after spinner
366+
if print_messages:
367+
print()
363368

364-
if task_message_update.parent_task_message and task_message_update.parent_task_message.id:
365-
finished_message = client.messages.retrieve(task_message_update.parent_task_message.id)
366-
messages_to_return.append(finished_message)
367-
print_task_message(finished_message, print_messages, rich_print)
369+
# Use the content directly from the stream event, not from re-fetching
370+
# The stream has the full content, but re-fetching sometimes returns empty arrays
371+
if task_message_update.parent_task_message:
372+
# Create a temporary message object with the stream content for display
373+
display_message = task_message_update.parent_task_message
374+
# Override the content with the stream's full content
375+
display_message.content = task_message_update.content
376+
377+
messages_to_return.append(display_message)
378+
print_task_message(display_message, print_messages, rich_print)
368379

369380
elif message_type == "done":
370381
task_message_update = StreamTaskMessageDone.model_validate(task_message_update_data)
@@ -374,12 +385,24 @@ def subscribe_to_async_task_messages(
374385
if index in active_spinners:
375386
active_spinners[index].stop()
376387
del active_spinners[index]
388+
# Ensure clean line after spinner
389+
if print_messages:
390+
print()
377391

378392
if task_message_update.parent_task_message and task_message_update.parent_task_message.id:
379393
finished_message = client.messages.retrieve(task_message_update.parent_task_message.id)
380394
messages_to_return.append(finished_message)
381395
print_task_message(finished_message, print_messages, rich_print)
382396

397+
# Clean stream termination - break on done event
398+
if print_messages:
399+
console = Console(width=80) if rich_print else None
400+
if console:
401+
console.print("[dim]Stream ended - received 'done' event[/dim]")
402+
else:
403+
print("Stream ended - received 'done' event")
404+
break
405+
383406
# Ignore "connected" message type
384407
elif message_type == "connected":
385408
pass

0 commit comments

Comments
 (0)