Skip to content

Commit 58059a6

Browse files
committed
support reasoning
1 parent 6b21e8c commit 58059a6

File tree

5 files changed

+577
-416
lines changed

5 files changed

+577
-416
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ dist
1313
.envrc
1414
codegen.log
1515
Brewfile.lock.json
16+
17+
.DS_Store

examples/tutorials/10_agentic/10_temporal/020_state_machine/dev.ipynb

Lines changed: 108 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
66
"id": "0",
77
"metadata": {},
88
"outputs": [],
@@ -14,7 +14,7 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": null,
17+
"execution_count": 2,
1818
"id": "1",
1919
"metadata": {},
2020
"outputs": [],
@@ -24,10 +24,18 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": null,
27+
"execution_count": 3,
2828
"id": "2",
2929
"metadata": {},
30-
"outputs": [],
30+
"outputs": [
31+
{
32+
"name": "stdout",
33+
"output_type": "stream",
34+
"text": [
35+
"Task(id='5d950471-ac85-4847-8102-209d0a79b0a6', created_at=datetime.datetime(2025, 8, 13, 0, 15, 24, 722362, tzinfo=TzInfo(UTC)), name='93ec41a3-task', status='RUNNING', status_reason='Task created, forwarding to ACP server', updated_at=datetime.datetime(2025, 8, 13, 0, 15, 24, 722362, tzinfo=TzInfo(UTC)))\n"
36+
]
37+
}
38+
],
3139
"source": [
3240
"# (REQUIRED) Create a new task. For Agentic agents, you must create a task for messages to be associated with.\n",
3341
"import uuid\n",
@@ -46,10 +54,18 @@
4654
},
4755
{
4856
"cell_type": "code",
49-
"execution_count": null,
57+
"execution_count": 4,
5058
"id": "3",
5159
"metadata": {},
52-
"outputs": [],
60+
"outputs": [
61+
{
62+
"name": "stdout",
63+
"output_type": "stream",
64+
"text": [
65+
"Event(id='75379175-48cc-4d45-93f5-0e2125e6465d', agent_id='71580630-2e43-4db2-912f-124a80d8aca4', sequence_id=1, task_id='5d950471-ac85-4847-8102-209d0a79b0a6', content=TextContent(author='user', content='Hello tell me the latest news about AI and AI startups', attachments=None, format='plain', style='static', type='text'), created_at=datetime.datetime(2025, 8, 13, 0, 15, 26, 693593, tzinfo=TzInfo(UTC)))\n"
66+
]
67+
}
68+
],
5369
"source": [
5470
"# Send an event to the agent\n",
5571
"\n",
@@ -75,10 +91,35 @@
7591
},
7692
{
7793
"cell_type": "code",
78-
"execution_count": null,
94+
"execution_count": 5,
7995
"id": "4",
8096
"metadata": {},
81-
"outputs": [],
97+
"outputs": [
98+
{
99+
"data": {
100+
"text/html": [
101+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #00ffff; text-decoration-color: #00ffff\">╭───────────────────────── </span><span style=\"color: #00ffff; text-decoration-color: #00ffff; font-weight: bold\">USER</span><span style=\"color: #00ffff; text-decoration-color: #00ffff\"> [08/13/2025 00:15:26] ─────────────────────────╮</span>\n",
102+
"<span style=\"color: #00ffff; text-decoration-color: #00ffff\">│</span> Hello tell me the latest news about AI and AI startups <span style=\"color: #00ffff; text-decoration-color: #00ffff\">│</span>\n",
103+
"<span style=\"color: #00ffff; text-decoration-color: #00ffff\">╰──────────────────────────────────────────────────────────────────────────────╯</span>\n",
104+
"</pre>\n"
105+
],
106+
"text/plain": [
107+
"\u001b[96m╭─\u001b[0m\u001b[96m────────────────────────\u001b[0m\u001b[96m \u001b[0m\u001b[1;96mUSER\u001b[0m\u001b[96m [08/13/2025 00:15:26] \u001b[0m\u001b[96m────────────────────────\u001b[0m\u001b[96m─╮\u001b[0m\n",
108+
"\u001b[96m│\u001b[0m Hello tell me the latest news about AI and AI startups \u001b[96m│\u001b[0m\n",
109+
"\u001b[96m╰──────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
110+
]
111+
},
112+
"metadata": {},
113+
"output_type": "display_data"
114+
},
115+
{
116+
"name": "stdout",
117+
"output_type": "stream",
118+
"text": [
119+
"Streaming timed out after 5 seconds - returning collected messages\n"
120+
]
121+
}
122+
],
82123
"source": [
83124
"# Subscribe to the async task messages produced by the agent\n",
84125
"from agentex.lib.utils.dev_tools import subscribe_to_async_task_messages\n",
@@ -95,10 +136,18 @@
95136
},
96137
{
97138
"cell_type": "code",
98-
"execution_count": null,
139+
"execution_count": 6,
99140
"id": "5",
100141
"metadata": {},
101-
"outputs": [],
142+
"outputs": [
143+
{
144+
"name": "stdout",
145+
"output_type": "stream",
146+
"text": [
147+
"Event(id='f0bbedb7-95db-4708-acc0-e3094f34036a', agent_id='71580630-2e43-4db2-912f-124a80d8aca4', sequence_id=2, task_id='5d950471-ac85-4847-8102-209d0a79b0a6', content=TextContent(author='user', content='I want to know what viral news came up and which startups failed, got acquired, or became very successful or popular in the last 3 months', attachments=None, format='plain', style='static', type='text'), created_at=datetime.datetime(2025, 8, 13, 0, 15, 32, 633013, tzinfo=TzInfo(UTC)))\n"
148+
]
149+
}
150+
],
102151
"source": [
103152
"# Send a follow up event to the agent in response to the agent's follow up question\n",
104153
"\n",
@@ -116,10 +165,56 @@
116165
},
117166
{
118167
"cell_type": "code",
119-
"execution_count": null,
168+
"execution_count": 7,
120169
"id": "6",
121170
"metadata": {},
122-
"outputs": [],
171+
"outputs": [
172+
{
173+
"data": {
174+
"text/html": [
175+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #00ffff; text-decoration-color: #00ffff\">╭───────────────────────── </span><span style=\"color: #00ffff; text-decoration-color: #00ffff; font-weight: bold\">USER</span><span style=\"color: #00ffff; text-decoration-color: #00ffff\"> [08/13/2025 00:15:32] ─────────────────────────╮</span>\n",
176+
"<span style=\"color: #00ffff; text-decoration-color: #00ffff\">│</span> I want to know what viral news came up and which startups failed, got <span style=\"color: #00ffff; text-decoration-color: #00ffff\">│</span>\n",
177+
"<span style=\"color: #00ffff; text-decoration-color: #00ffff\">│</span> acquired, or became very successful or popular in the last 3 months <span style=\"color: #00ffff; text-decoration-color: #00ffff\">│</span>\n",
178+
"<span style=\"color: #00ffff; text-decoration-color: #00ffff\">╰──────────────────────────────────────────────────────────────────────────────╯</span>\n",
179+
"</pre>\n"
180+
],
181+
"text/plain": [
182+
"\u001b[96m╭─\u001b[0m\u001b[96m────────────────────────\u001b[0m\u001b[96m \u001b[0m\u001b[1;96mUSER\u001b[0m\u001b[96m [08/13/2025 00:15:32] \u001b[0m\u001b[96m────────────────────────\u001b[0m\u001b[96m─╮\u001b[0m\n",
183+
"\u001b[96m│\u001b[0m I want to know what viral news came up and which startups failed, got \u001b[96m│\u001b[0m\n",
184+
"\u001b[96m│\u001b[0m acquired, or became very successful or popular in the last 3 months \u001b[96m│\u001b[0m\n",
185+
"\u001b[96m╰──────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
186+
]
187+
},
188+
"metadata": {},
189+
"output_type": "display_data"
190+
},
191+
{
192+
"data": {
193+
"text/html": [
194+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">╭──────────────────────── </span><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">AGENT</span><span style=\"color: #008000; text-decoration-color: #008000\"> [08/13/2025 00:15:32] ─────────────────────────╮</span>\n",
195+
"<span style=\"color: #008000; text-decoration-color: #008000\">│</span> Starting deep research process based on your query and follow-up <span style=\"color: #008000; text-decoration-color: #008000\">│</span>\n",
196+
"<span style=\"color: #008000; text-decoration-color: #008000\">│</span> responses... <span style=\"color: #008000; text-decoration-color: #008000\">│</span>\n",
197+
"<span style=\"color: #008000; text-decoration-color: #008000\">╰──────────────────────────────────────────────────────────────────────────────╯</span>\n",
198+
"</pre>\n"
199+
],
200+
"text/plain": [
201+
"\u001b[32m╭─\u001b[0m\u001b[32m───────────────────────\u001b[0m\u001b[32m \u001b[0m\u001b[1;32mAGENT\u001b[0m\u001b[32m [08/13/2025 00:15:32] \u001b[0m\u001b[32m────────────────────────\u001b[0m\u001b[32m─╮\u001b[0m\n",
202+
"\u001b[32m│\u001b[0m Starting deep research process based on your query and follow-up \u001b[32m│\u001b[0m\n",
203+
"\u001b[32m│\u001b[0m responses... \u001b[32m│\u001b[0m\n",
204+
"\u001b[32m╰──────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
205+
]
206+
},
207+
"metadata": {},
208+
"output_type": "display_data"
209+
},
210+
{
211+
"name": "stdout",
212+
"output_type": "stream",
213+
"text": [
214+
"Streaming timed out after 30 seconds - returning collected messages\n"
215+
]
216+
}
217+
],
123218
"source": [
124219
"# Subscribe to the async task messages produced by the agent\n",
125220
"from agentex.lib.utils.dev_tools import subscribe_to_async_task_messages\n",
@@ -159,7 +254,7 @@
159254
"name": "python",
160255
"nbconvert_exporter": "python",
161256
"pygments_lexer": "ipython3",
162-
"version": "3.12.9"
257+
"version": "3.12.11"
163258
}
164259
},
165260
"nbformat": 4,

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ dependencies = [
3838
"pytest>=8.4.0",
3939
"pytest-asyncio>=1.0.0",
4040
"scale-gp-beta==0.1.0a20",
41-
"ipykernel>=6.29.5",
41+
"ipykernel>=6.29.5",
42+
"openai>=1.99.9",
4243
]
4344
requires-python = ">= 3.12,<4"
4445
classifiers = [

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
)
3030
from agentex.types.task_message_content import (
3131
TextContent,
32+
ReasoningContent,
3233
ToolRequestContent,
3334
ToolResponseContent,
3435
)
@@ -647,6 +648,31 @@ async def run_agent_streamed_auto_send(
647648
content=tool_response_content,
648649
),
649650
)
651+
652+
elif event.item.type == "reasoning_item":
653+
# Handle reasoning items
654+
reasoning_item = event.item.raw_item
655+
656+
reasoning_content = ReasoningContent(
657+
author="agent",
658+
summary=[summary.text for summary in reasoning_item.summary],
659+
content=[content.text for content in reasoning_item.content] if reasoning_item.content else None,
660+
)
661+
662+
# Create reasoning content using streaming context (immediate completion)
663+
async with (
664+
self.streaming_service.streaming_task_message_context(
665+
task_id=task_id,
666+
initial_content=reasoning_content,
667+
) as streaming_context
668+
):
669+
# The message has already been persisted, but we still need to send an update
670+
await streaming_context.stream_update(
671+
update=StreamTaskMessageFull(
672+
parent_task_message=streaming_context.task_message,
673+
content=reasoning_content,
674+
),
675+
)
650676

651677
elif event.type == "raw_response_event":
652678
if isinstance(event.data, ResponseTextDeltaEvent):

0 commit comments

Comments
 (0)