Skip to content

Add support for tool execution - #41

Merged
krypticmouse merged 3 commits into
mainfrom
tool-support
Nov 7, 2025
Merged

Add support for tool execution#41
krypticmouse merged 3 commits into
mainfrom
tool-support

Conversation

@krypticmouse

Copy link
Copy Markdown
Owner

This pull request adds support for tool calls to the dspy-rs library, enabling language models to interact with external tools during chat completions. The changes introduce a new ToolDyn trait object for passing tools, update the adapter and predictor interfaces to accept tools, implement the tool execution loop in the language model, and provide tests for tool call functionality.

Tool Call Support Integration

  • Added a ToolDyn trait object and updated relevant imports to support dynamic tool handling across the adapter, core, and predictor modules. [1] [2] [3] [4]
  • Updated the Adapter trait, ChatAdapter, and Predict predictor to accept and forward a list of tools for use during prediction and chat completion. [1] [2] [3]

Language Model Execution Loop

  • Implemented a tool execution loop in the LM struct, allowing the model to handle tool calls, execute tools, and continue the conversation until a text response is generated or a maximum iteration count is reached. [1] [2]
  • Modified the LM::call method to process tool definitions, set tool choice, and correctly accumulate token usage across tool calls. [1] [2]

Utilities and Testing

  • Added a NoTool placeholder type to handle cases where no tools are provided, improving error handling and interface clarity.
  • Added comprehensive tests for tool call scenarios, including a mock calculator tool and cases with and without tools, to validate the new functionality.

Closes #33

@krypticmouse
krypticmouse merged commit fb604fc into main Nov 7, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Functionality to Support Tool Use

1 participant