Skip to content

Commit e0833e3

Browse files
CopilotTomeHirata
andcommitted
Use ToolCalls class for next_tool_calls schema
- Changed type annotation from list[dict[str, Any]] to ToolCalls - Updated _parse_tool_calls to handle ToolCalls objects - Added ToolCalls to imports - All tests passing with proper linting Co-authored-by: TomeHirata <[email protected]>
1 parent 741ac11 commit e0833e3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

dspy/predict/react.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from litellm import ContextWindowExceededError
77

88
import dspy
9-
from dspy.adapters.types.tool import Tool
9+
from dspy.adapters.types.tool import Tool, ToolCalls
1010
from dspy.primitives.module import Module
1111
from dspy.signatures.signature import ensure_signature
1212

@@ -81,7 +81,7 @@ def get_weather(city: str) -> str:
8181
dspy.Signature({**signature.input_fields}, "\n".join(instr))
8282
.append("trajectory", dspy.InputField(), type_=str)
8383
.append("next_thought", dspy.OutputField(), type_=str)
84-
.append("next_tool_calls", dspy.OutputField(), type_=list[dict[str, Any]])
84+
.append("next_tool_calls", dspy.OutputField(), type_=ToolCalls)
8585
)
8686

8787
fallback_signature = dspy.Signature(
@@ -173,8 +173,12 @@ async def aforward(self, **input_args):
173173
def _parse_tool_calls(self, tool_calls_data):
174174
"""Parse tool calls from the prediction output.
175175
176-
Handles both the new list format and provides backward compatibility.
176+
Handles both ToolCalls objects and list formats for backward compatibility.
177177
"""
178+
# If it's a ToolCalls object, extract the list of tool calls
179+
if isinstance(tool_calls_data, ToolCalls):
180+
return [{"name": tc.name, "args": tc.args} for tc in tool_calls_data.tool_calls]
181+
178182
# If it's already a list of dicts with 'name' and 'args', use it directly
179183
if isinstance(tool_calls_data, list):
180184
return tool_calls_data

0 commit comments

Comments
 (0)