@sisu-ai/mw-tool-calling
v10.0.0
Published
Execute provider-native tool call loops with robust iteration, validation, and tool result handling.
Maintainers
Readme
@sisu-ai/mw-tool-calling
Execute provider-native tool call loops with robust iteration, validation, and tool result handling.
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);Tool Execution Records
Each executed tool call is appended to ctx.state.toolExecutions:
type ToolExecutionRecord = {
aliasName: string;
canonicalName: string;
callId?: string;
args: unknown;
result: unknown;
};This is useful for diagnostics and post-run inspection without manually parsing tool messages.
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.
Documentation
Core — Package docs · Error types
Adapters — OpenAI · Anthropic · Ollama
- @sisu-ai/mw-agent-run-api
- @sisu-ai/mw-context-compressor
- @sisu-ai/mw-control-flow
- @sisu-ai/mw-conversation-buffer
- @sisu-ai/mw-cors
- @sisu-ai/mw-error-boundary
- @sisu-ai/mw-guardrails
- @sisu-ai/mw-invariants
- @sisu-ai/mw-orchestration
- @sisu-ai/mw-rag
- @sisu-ai/mw-react-parser
- @sisu-ai/mw-register-tools
- @sisu-ai/mw-tool-calling
- @sisu-ai/mw-trace-viewer
- @sisu-ai/mw-usage-tracker
- @sisu-ai/tool-aws-s3
- @sisu-ai/tool-azure-blob
- @sisu-ai/tool-extract-urls
- @sisu-ai/tool-github-projects
- @sisu-ai/tool-rag
- @sisu-ai/tool-summarize-text
- @sisu-ai/tool-terminal
- @sisu-ai/tool-web-fetch
- @sisu-ai/tool-web-search-duckduckgo
- @sisu-ai/tool-web-search-google
- @sisu-ai/tool-web-search-openai
- @sisu-ai/tool-wikipedia
Anthropic — hello · control-flow · stream · weather
Ollama — hello · stream · vision · weather · web-search
OpenAI — hello · weather · stream · vision · reasoning · react · control-flow · branch · parallel · graph · orchestration · orchestration-adaptive · guardrails · error-handling · rag-chroma · web-search · web-fetch · wikipedia · terminal · github-projects · server · aws-s3 · azure-blob
Contributing
We build Sisu in the open. Contributions welcome.
Contributing Guide · Report a Bug · Request a Feature · Code of Conduct
Star on GitHub if Sisu helps you build better agents.
Quiet, determined, relentlessly useful.
