@sisu-ai/mw-tool-calling
v9.0.0
Published
Native tools API loop for providers that support tool calls.
Maintainers
Readme
@sisu-ai/mw-tool-calling
Native tools API loop for providers that support tool calls.
Setup
npm i @sisu-ai/mw-tool-callingBehavior
toolCalling: single-round tool calling.- First turn: calls
ctx.model.generate(messages, { tools, toolChoice:'auto' }). - If assistant returns
tool_calls, appends the assistant message and executes each tool.- Executes each unique
(name, args)once and responds to everytool_call_id. - Handles provider quirks by reusing last args for identical tool names with missing args.
- Executes each unique
- Second turn: asks for a pure completion (
toolChoice:'none').
- First turn: calls
sequenceDiagram
autonumber
participant A as Agent toolCalling
participant M as Model Adapter
participant R as Tools Registry
participant H as Tool Handler
A->>R: list
R-->>A: tools
A->>M: generate with tools auto
alt tool calls
M-->>A: assistant with tool calls
loop each unique name args
A->>R: resolve and validate
R-->>A: handler
A->>H: execute
H-->>A: append tool message
end
A->>M: generate finalize none
M-->>A: assistant completion
else no tool calls
M-->>A: assistant completion
end
iterativeToolCalling: multi-round tool calling.- Repeats calls with
toolChoice:'auto'until the model returns a message with notool_calls(max 12 iters).
- Repeats calls with
sequenceDiagram
autonumber
participant A as Agent iterativeToolCalling
participant M as Model Adapter
participant R as Tools Registry
participant H as Tool Handler
A->>R: list
R-->>A: tools
loop max twelve iterations until no tool calls
A->>M: generate with tools auto
alt tool calls present
M-->>A: assistant with tool calls
loop each unique name args
A->>R: resolve and validate
R-->>A: handler
A->>H: execute
H-->>A: append tool message
end
else no tool calls
M-->>A: assistant no tools
end
end
A->>M: generate finalize none
M-->>A: assistant completionUsage
import { toolCalling, iterativeToolCalling } from '@sisu-ai/mw-tool-calling';
// Single-round
agent.use(toolCalling);
// OR multi-round
agent.use(iterativeToolCalling);Community & Support
Discover what you can do through examples or documentation. Check it out at https://github.com/finger-gun/sisu. Example projects live under examples/ in the repo.
