Skip to content

Commit 5ffa9cf

Browse files
fix: populate ChatRequest.tools and fix ToolCall attribute references
Changes: - Populate ChatRequest.tools with ToolSpec objects when creating requests - Fix ToolCall attribute references from .tool to .name (2 instances) - Add ToolSpec import for proper tool specification conversion This ensures tools are properly passed to providers in the typed ChatRequest format and tool calls are correctly processed using the .name attribute. 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
1 parent f8204c5 commit 5ffa9cf

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

amplifier_module_loop_basic/__init__.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from amplifier_core.events import TOOL_PRE
2727
from amplifier_core.message_models import ChatRequest
2828
from amplifier_core.message_models import Message
29+
from amplifier_core.message_models import ToolSpec
2930

3031
logger = logging.getLogger(__name__)
3132

@@ -132,7 +133,16 @@ async def execute(
132133
# Convert to ChatRequest with Message objects
133134
try:
134135
messages_objects = [Message(**msg) for msg in message_dicts]
135-
chat_request = ChatRequest(messages=messages_objects)
136+
137+
# Convert tools to ToolSpec format for ChatRequest
138+
tools_list = None
139+
if tools:
140+
tools_list = [
141+
ToolSpec(name=t.name, description=t.description, parameters=t.input_schema)
142+
for t in tools.values()
143+
]
144+
145+
chat_request = ChatRequest(messages=messages_objects, tools=tools_list)
136146
logger.debug(f"Created ChatRequest with {len(messages_objects)} messages")
137147
logger.debug(f"Message roles: {[m.role for m in chat_request.messages]}")
138148
except Exception as e:
@@ -141,11 +151,8 @@ async def execute(
141151
raise
142152
try:
143153
if hasattr(provider, "complete"):
144-
# Pass tools and extended_thinking if configured
145-
kwargs = {}
146-
if tools:
147-
kwargs["tools"] = list(tools.values())
148154
# Pass extended_thinking if enabled in orchestrator config
155+
kwargs = {}
149156
if self.extended_thinking:
150157
kwargs["extended_thinking"] = True
151158
response = await provider.complete(chat_request, **kwargs)
@@ -192,7 +199,7 @@ async def execute(
192199
"tool_calls": [
193200
{
194201
"id": getattr(tc, "id", None) or tc.get("id"),
195-
"tool": getattr(tc, "tool", None) or tc.get("tool"),
202+
"tool": getattr(tc, "name", None) or tc.get("tool"),
196203
"arguments": getattr(tc, "arguments", None) or tc.get("arguments") or {},
197204
}
198205
for tc in tool_calls
@@ -214,7 +221,7 @@ async def execute_single_tool(tc: Any, group_id: str) -> tuple[str, str]:
214221
Always returns (tool_call_id, result_or_error) tuple.
215222
Never raises - errors become error results.
216223
"""
217-
tool_name = getattr(tc, "tool", None) or tc.get("tool")
224+
tool_name = getattr(tc, "name", None) or tc.get("tool")
218225
tool_call_id = getattr(tc, "id", None) or tc.get("id")
219226
args = getattr(tc, "arguments", None) or tc.get("arguments") or {}
220227
tool = tools.get(tool_name)
@@ -363,11 +370,18 @@ async def execute_single_tool(tc: Any, group_id: str) -> tuple[str, str]:
363370

364371
try:
365372
messages_objects = [Message(**msg) for msg in message_dicts]
366-
chat_request = ChatRequest(messages=messages_objects)
367373

368-
kwargs = {}
374+
# Convert tools to ToolSpec format for ChatRequest
375+
tools_list = None
369376
if tools:
370-
kwargs["tools"] = list(tools.values())
377+
tools_list = [
378+
ToolSpec(name=t.name, description=t.description, parameters=t.input_schema)
379+
for t in tools.values()
380+
]
381+
382+
chat_request = ChatRequest(messages=messages_objects, tools=tools_list)
383+
384+
kwargs = {}
371385
if self.extended_thinking:
372386
kwargs["extended_thinking"] = True
373387

0 commit comments

Comments
 (0)