Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/docs/learn/programming/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ react_agent = dspy.ReAct(

For more control over the tool calling process, you can manually handle tools using DSPy's tool types.

!!! note "Version Requirement"
The `ToolCall.execute()` method used in the examples below is available from **dspy 3.0.4b2** onwards. If you're using version 3.0.3 or earlier, you'll need to upgrade to use this feature.
Copy link
Collaborator

@TomeHirata TomeHirata Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Can we also document that users need to call tools[call.name](**call.args) in the earlier versions? We can include this as a comment in the code example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added workaround documentation in commit 1723bc5.

The code examples now include:

  1. In the Basic Setup section: an inline comment showing result = tools[call.name](**call.args) for pre-3.0.4b2 versions
  2. In the Understanding ToolCalls section: an "Option 4" showing the manual tool lookup pattern for backward compatibility


### Basic Setup

```python
Expand Down Expand Up @@ -108,6 +111,7 @@ response = predictor(
for call in response.outputs.tool_calls:
# Execute the tool call
result = call.execute()
# For versions earlier than 3.0.4b2, use: result = tools[call.name](**call.args)
print(f"Tool: {call.name}")
print(f"Args: {call.args}")
print(f"Result: {result}")
Expand All @@ -134,6 +138,9 @@ print(str(tool)) # Full tool description

### Understanding `dspy.ToolCalls`

!!! note "Version Requirement"
The `ToolCall.execute()` method is available from **dspy 3.0.4b2** onwards. If you're using an earlier version, you'll need to upgrade to use this feature.

The `dspy.ToolCalls` type represents the output from a model that can make tool calls. Each individual tool call can be executed using the `execute` method:

```python
Expand All @@ -153,6 +160,10 @@ for call in response.outputs.tool_calls:
# Option 3: Pass Tool objects as a list
result = call.execute(functions=[dspy.Tool(weather), dspy.Tool(calculator)])

# Option 4: For versions earlier than 3.0.4b2 (manual tool lookup)
# tools_dict = {"weather": weather, "calculator": calculator}
# result = tools_dict[call.name](**call.args)

print(f"Result: {result}")
```

Expand Down