Skip to content

Commit 6404e14

Browse files
authored
Merge pull request #75 from scaleapi/fs/reasoning
support reasoning
2 parents 3b40067 + c91825b commit 6404e14

File tree

6 files changed

+479
-404
lines changed

6 files changed

+479
-404
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/010_agent_chat/project/workflow.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from agentex.lib.utils.model_utils import BaseModel
77
from mcp import StdioServerParameters
88
from temporalio import workflow
9+
from agents import ModelSettings
10+
from openai.types.shared import Reasoning
911

1012
from agentex.lib import adk
1113
from agentex.lib.types.acp import CreateTaskParams, SendEventParams
@@ -117,6 +119,13 @@ async def on_task_event_send(self, params: SendEventParams) -> None:
117119
You have access to sequential thinking and web search capabilities through MCP servers.
118120
Use these tools when appropriate to provide accurate and well-reasoned responses.""",
119121
parent_span_id=span.id if span else None,
122+
model="o4-mini",
123+
model_settings=ModelSettings(
124+
# Include reasoning items in the response (IDs, summaries)
125+
# response_include=["reasoning.encrypted_content"],
126+
# Ask the model to include a short reasoning summary
127+
reasoning=Reasoning(effort="medium", summary="auto"),
128+
)
120129
)
121130
self._state.input_list = run_result.final_input_list
122131

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
"name": "python",
160160
"nbconvert_exporter": "python",
161161
"pygments_lexer": "ipython3",
162-
"version": "3.12.9"
162+
"version": "3.12.11"
163163
}
164164
},
165165
"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)