toolsplice 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -330
- package/dist/abortable.d.ts +6 -0
- package/dist/abortable.js +50 -0
- package/dist/adaptive-read.d.ts +50 -0
- package/dist/adaptive-read.js +780 -0
- package/dist/answer-wait.d.ts +7 -0
- package/dist/answer-wait.js +45 -0
- package/dist/cache-reads.d.ts +18 -0
- package/dist/cache-reads.js +89 -0
- package/dist/calibration-ledger.d.ts +37 -0
- package/dist/calibration-ledger.js +148 -0
- package/dist/calibration-marker.d.ts +4 -0
- package/dist/calibration-marker.js +77 -0
- package/dist/catalog-setup.d.ts +33 -0
- package/dist/catalog-setup.js +89 -0
- package/dist/catalog.d.ts +10 -0
- package/dist/catalog.js +42 -0
- package/dist/checkpoint-files.d.ts +15 -0
- package/dist/checkpoint-files.js +99 -0
- package/dist/cli.js +545 -14
- package/dist/coalesce-reads.d.ts +6 -0
- package/dist/coalesce-reads.js +33 -0
- package/dist/contract-caller.d.ts +2 -1
- package/dist/contract-caller.js +35 -16
- package/dist/contract-schema.d.ts +3 -1
- package/dist/contract-schema.js +34 -4
- package/dist/contracts.d.ts +1 -0
- package/dist/contracts.js +5 -1
- package/dist/core.d.ts +31 -1
- package/dist/core.js +27 -0
- package/dist/db-final-answer.d.ts +9 -0
- package/dist/db-final-answer.js +62 -0
- package/dist/define.d.ts +78 -0
- package/dist/define.js +14 -0
- package/dist/final-answer-stores.d.ts +71 -0
- package/dist/final-answer-stores.js +72 -0
- package/dist/final-answer.d.ts +32 -0
- package/dist/final-answer.js +104 -0
- package/dist/impact.d.ts +48 -0
- package/dist/impact.js +71 -0
- package/dist/index.d.ts +32 -1
- package/dist/index.js +28 -0
- package/dist/local-tool.d.ts +18 -0
- package/dist/local-tool.js +32 -0
- package/dist/mcp-apps.d.ts +53 -0
- package/dist/mcp-apps.js +32 -0
- package/dist/mcp-event-delivery.d.ts +98 -0
- package/dist/mcp-event-delivery.js +211 -0
- package/dist/mcp-extensions.d.ts +46 -0
- package/dist/mcp-extensions.js +200 -0
- package/dist/mcp-peer.d.ts +45 -0
- package/dist/mcp-peer.js +207 -0
- package/dist/mcp-server-card.d.ts +21 -0
- package/dist/mcp-server-card.js +54 -0
- package/dist/page-checkpoint.d.ts +71 -0
- package/dist/page-checkpoint.js +286 -0
- package/dist/page-read-gate.d.ts +15 -0
- package/dist/page-read-gate.js +48 -0
- package/dist/pattern.d.ts +1 -0
- package/dist/pattern.js +27 -5
- package/dist/probe.js +6 -19
- package/dist/read-pages.d.ts +25 -0
- package/dist/read-pages.js +85 -0
- package/dist/read-policy.d.ts +6 -0
- package/dist/read-policy.js +16 -0
- package/dist/read-steps.d.ts +12 -0
- package/dist/read-steps.js +36 -0
- package/dist/result-session.d.ts +109 -0
- package/dist/result-session.js +620 -0
- package/dist/route-checkpoint.d.ts +3 -0
- package/dist/route-checkpoint.js +80 -0
- package/dist/route-driver-cli.d.ts +3 -0
- package/dist/route-driver-cli.js +43 -0
- package/dist/route-evaluation.d.ts +141 -0
- package/dist/route-evaluation.js +329 -0
- package/dist/row-groups.d.ts +17 -0
- package/dist/row-groups.js +79 -0
- package/dist/row-query.d.ts +62 -0
- package/dist/row-query.js +172 -0
- package/dist/rules.d.ts +30 -0
- package/dist/rules.js +72 -0
- package/dist/run-diagnostics.d.ts +75 -0
- package/dist/run-diagnostics.js +212 -0
- package/dist/search-fetch.d.ts +50 -0
- package/dist/search-fetch.js +264 -0
- package/dist/skill-files.d.ts +9 -0
- package/dist/skill-files.js +49 -0
- package/dist/splice-diagnostics.d.ts +4 -0
- package/dist/splice-diagnostics.js +24 -16
- package/dist/splice-measure.d.ts +33 -0
- package/dist/splice-measure.js +55 -0
- package/dist/splice-project.d.ts +12 -6
- package/dist/splice-project.js +72 -20
- package/dist/splice-recording.d.ts +29 -2
- package/dist/splice-recording.js +22 -5
- package/dist/splice.d.ts +98 -1
- package/dist/splice.js +225 -27
- package/dist/sqlite-checkpoint-store.d.ts +5 -0
- package/dist/sqlite-checkpoint-store.js +91 -0
- package/dist/sqlite-checkpoint-worker.d.ts +1 -0
- package/dist/sqlite-checkpoint-worker.js +115 -0
- package/dist/test-difference.d.ts +13 -0
- package/dist/test-difference.js +42 -0
- package/dist/testing.d.ts +122 -0
- package/dist/testing.js +261 -0
- package/dist/text-pages.d.ts +24 -0
- package/dist/text-pages.js +36 -0
- package/dist/tool-discovery.d.ts +59 -0
- package/dist/tool-discovery.js +136 -0
- package/dist/unevaluated.d.ts +7 -0
- package/dist/unevaluated.js +156 -0
- package/dist/v2.js +25 -8
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workflow-json.js +1 -1
- package/docs/AGENT-FRAMEWORKS.md +431 -0
- package/docs/BENCHMARKS.md +43 -0
- package/docs/INTEGRATION-QUICKSTART.md +859 -0
- package/docs/LEARNING-AND-STORAGE.md +393 -0
- package/docs/MCP.md +204 -0
- package/docs/PROJECTS-AND-UPGRADES.md +67 -9
- package/docs/PYTHON-REFERENCE.md +348 -0
- package/docs/PYTHON.md +120 -0
- package/docs/RECORDING-AND-CORRECTIONS.md +30 -1
- package/docs/TESTING.md +259 -0
- package/examples/mcp-app/build.mjs +11 -0
- package/examples/mcp-app/view.mjs +22 -0
- package/examples/quickstart.mjs +43 -0
- package/examples/route-driver.mjs +67 -0
- package/integrations/ai.d.mts +36 -0
- package/integrations/ai.mjs +178 -0
- package/integrations/call-options.mjs +9 -0
- package/integrations/langchain.d.mts +31 -0
- package/integrations/langchain.mjs +114 -0
- package/integrations/managed.mjs +154 -0
- package/integrations/types.d.mts +13 -0
- package/package.json +47 -3
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
# Use a Toolsplice workflow in an agent
|
|
2
|
+
|
|
3
|
+
For adaptive tools in a new or existing app, start with the [direct, Agno, LangChain and AI SDK quickstart](INTEGRATION-QUICKSTART.md).
|
|
4
|
+
|
|
5
|
+
A prepared splice can be one tool in an existing agent. Bind the source and destination callers once. The framework advertises the source input schema to the model. On success the agent receives `{"results":[...]}` with the fields you selected. Keep the native tools available for tasks outside the workflow.
|
|
6
|
+
|
|
7
|
+
## Install the integration you use
|
|
8
|
+
|
|
9
|
+
Choose the command for your framework. Run it in the environment where your agent runs.
|
|
10
|
+
|
|
11
|
+
| Framework | Install |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| Agno | `python -m pip install 'toolsplice[agno]==0.0.2'` |
|
|
14
|
+
| LangChain Python | `python -m pip install 'toolsplice[langchain]==0.0.2' 'langchain>=1,<2'` |
|
|
15
|
+
| Vercel AI SDK | `npm install toolsplice@0.0.2 'ai@>=6 <8'` |
|
|
16
|
+
| LangChain JS | `npm install toolsplice@0.0.2 langchain@^1 @langchain/core@^1` |
|
|
17
|
+
|
|
18
|
+
Keep your existing model provider and the MCP connections your app has authorized.
|
|
19
|
+
|
|
20
|
+
## Python
|
|
21
|
+
|
|
22
|
+
Create the workflow from a splice you have prepared using your source and destination contracts. Supply a description that states the input boundary and the returned fields.
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
workflow = prepared.as_tool(
|
|
26
|
+
name="count_large_quakes",
|
|
27
|
+
description="Count USGS earthquakes for the supplied dates and magnitude. Return the count.",
|
|
28
|
+
source=build_query.caller,
|
|
29
|
+
target=earthquake_caller,
|
|
30
|
+
)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Agno
|
|
34
|
+
|
|
35
|
+
Install Toolsplice with the `agno` extra if your app needs Agno. Pass the workflow to the same agent as your other tools and use its async entry point.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from agno.agent import Agent
|
|
39
|
+
from toolsplice.integrations.agno import as_agno_tool
|
|
40
|
+
|
|
41
|
+
agent = Agent(model=model, tools=[as_agno_tool(workflow)])
|
|
42
|
+
response = await agent.arun("How many magnitude-6.5 earthquakes occurred in April 2024?")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
For streaming, iterate over `agent.arun(question, stream=True)`. Agno receives JSON text from this adapter. Nested objects, booleans and nulls retain their JSON representations.
|
|
46
|
+
|
|
47
|
+
### LangChain
|
|
48
|
+
|
|
49
|
+
The `langchain` extra installs the structured-tool dependency. Applications using `create_agent` also need the LangChain agent package and their chosen model provider.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from langchain.agents import create_agent
|
|
53
|
+
from toolsplice.integrations.langchain import as_langchain_tool
|
|
54
|
+
|
|
55
|
+
agent = create_agent(model=model, tools=[as_langchain_tool(workflow)])
|
|
56
|
+
state = await agent.ainvoke({
|
|
57
|
+
"messages": [{"role": "user", "content": "Count magnitude-6.5 earthquakes in April 2024."}]
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
LangChain Python propagates workflow exceptions to the application by default. To let the agent see a checked tool failure, register `as_langchain_tool(workflow, handle_tool_error=True)`. LangChain then supplies an error tool message. In a read-only agent you can ask the model to retry once. For a workflow that writes data, use the failure’s `completedTargets` and `destinationMayHaveRun` fields to decide how the application should recover.
|
|
62
|
+
|
|
63
|
+
Both adapters accept application-owned run options at registration. For a reviewed mapping with required trusted context, use `as_agno_tool(workflow, allow_review=True, context={"catalog": "usgs"})` or pass the same options to `as_langchain_tool`. Bind request-specific context when constructing the tool for that request.
|
|
64
|
+
|
|
65
|
+
## JavaScript and TypeScript
|
|
66
|
+
|
|
67
|
+
If your app supplies its own MCP clients, the standalone `toolsplice-core` package exposes the same helpers at `toolsplice-core/ai` and `toolsplice-core/langchain`. Install only the framework that your application uses.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const workflow = prepared.asTool({
|
|
71
|
+
name: "count_large_quakes",
|
|
72
|
+
description: "Count USGS earthquakes for the supplied dates and magnitude. Return the count.",
|
|
73
|
+
source: buildQuery.caller,
|
|
74
|
+
target: earthquakeCaller,
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Vercel AI SDK
|
|
79
|
+
|
|
80
|
+
`aiTools` returns a tool set keyed by the workflow name. Spread the set alongside the other tools in your app.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { generateText, stepCountIs } from "ai";
|
|
84
|
+
import { aiTools } from "toolsplice/ai";
|
|
85
|
+
|
|
86
|
+
const response = await generateText({
|
|
87
|
+
model,
|
|
88
|
+
tools: { ...aiTools(workflow) },
|
|
89
|
+
prompt: "Count magnitude-6.5 earthquakes in April 2024.",
|
|
90
|
+
stopWhen: stepCountIs(3),
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The same tool set works with `streamText`. Consume the stream to observe the tool result and final text.
|
|
95
|
+
|
|
96
|
+
### LangChain
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { createAgent } from "langchain";
|
|
100
|
+
import { asLangChainTool } from "toolsplice/langchain";
|
|
101
|
+
|
|
102
|
+
const agent = createAgent({ model, tools: [asLangChainTool(workflow)] });
|
|
103
|
+
const state = await agent.invoke({
|
|
104
|
+
messages: [{ role: "user", content: "Count magnitude-6.5 earthquakes in April 2024." }],
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The JS adapters accept a second argument with Toolsplice run options, such as `{ context: { catalog: "usgs" }, allowReview: true }`. Either an application abort signal or framework cancellation can stop an in-flight workflow.
|
|
109
|
+
|
|
110
|
+
### Deliver a checked tool result directly
|
|
111
|
+
|
|
112
|
+
If a workflow produces the entire requested JSON response, the host can return its result as soon as that tool succeeds. This avoids paying for the model to restate fields such as IDs, revision hashes and exact URLs. Keep the response contract in the application.
|
|
113
|
+
|
|
114
|
+
- In Agno, register `as_agno_tool(workflow, return_direct=True)`. Inspect the terminal tool execution before accepting its JSON. In the live failure test, Agno stopped after a provider error and its response content was empty. Check the tool name, `tool_call_error` and expected output shape.
|
|
115
|
+
- In LangChain, register `as_langchain_tool(workflow, return_direct=True)` or `asLangChainTool(workflow, { returnDirect: true })`. Use the successful terminal tool message as the result and handle framework error messages separately.
|
|
116
|
+
- In Vercel AI SDK, supply a `stopWhen` condition that checks for one successful terminal tool result in the current step. Read that result's `output` and validate its shape. Retain a maximum step count for other paths.
|
|
117
|
+
|
|
118
|
+
For example, if the terminal Agno tool returns an object with a `reports` array, accept the result of the successful tool execution before passing it to the caller.
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
import json
|
|
122
|
+
|
|
123
|
+
run = await agent.arun(question)
|
|
124
|
+
last = (run.tools or [])[-1] if run.tools else None
|
|
125
|
+
if last is None or last.tool_name != workflow.definition["name"] or last.tool_call_error:
|
|
126
|
+
raise RuntimeError("The requested workflow did not complete.")
|
|
127
|
+
data = json.loads(last.result) # as_agno_tool returns successful results as JSON text
|
|
128
|
+
if not isinstance(data, dict) or not isinstance(data.get("reports"), list):
|
|
129
|
+
raise ValueError("Unexpected workflow result.")
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Choose a terminal tool only when it can satisfy the whole request. A list of ticket IDs and a count are different answer contracts. [Agno terminal tools](https://docs.agno.com/examples/tools/tool-decorator/stop-after-tool-call) · [LangChain returnDirect](https://reference.langchain.com/javascript/langchain-core/tools/Tool/returnDirect) · [Vercel AI SDK stop conditions](https://ai-sdk.dev/docs/reference/ai-sdk-core/generate-text)
|
|
133
|
+
|
|
134
|
+
## Give a multi-server workflow a small input schema
|
|
135
|
+
|
|
136
|
+
An agent might know a checkpoint name while the native search tools expect filesystem operations and a repository filter. Put that translation in an application function. Declare a tool with `defineLocalTool` or `define_local_tool` and pass it to the same framework adapter. The tool can call prepared splices, MCP clients and local code. The framework sees its declared input schema and final JSON value.
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from toolsplice import define_local_tool
|
|
140
|
+
from toolsplice.integrations.agno import as_agno_tool
|
|
141
|
+
|
|
142
|
+
lookup = define_local_tool(
|
|
143
|
+
{
|
|
144
|
+
"name": "converter_registration",
|
|
145
|
+
"description": "Look up a checkpoint and return its architecture and converter module.",
|
|
146
|
+
"inputSchema": {
|
|
147
|
+
"type": "object",
|
|
148
|
+
"properties": {"checkpoint": {"type": "string"}},
|
|
149
|
+
"required": ["checkpoint"],
|
|
150
|
+
"additionalProperties": False,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
lookup_checkpoint, # async function accepting one dict
|
|
154
|
+
)
|
|
155
|
+
agent = Agent(model=model, tools=[as_agno_tool(lookup)])
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
In JS, register the result of `defineLocalTool(definition, lookupCheckpoint)` with `aiTools(lookup)` or `asLangChainTool(lookup)`. The source checkout includes the tested Hugging Face → Grep implementation for each language in `bench/frameworks/live-cases.mjs` and `bench/frameworks/live_cases.py`. Place splice-specific context and review options at the inner splice call when you register a local function.
|
|
159
|
+
|
|
160
|
+
## Inspect a result on its first use
|
|
161
|
+
|
|
162
|
+
Create a `ResultSession` for each authenticated agent run. It wraps your existing Toolsplice tools or an authorized MCP catalog and its connected caller. A small JSON result is wrapped as `{"value": ...}`. A large one returns a random reference, its byte count, JSON type and a bounded preview. The full value stays in that process. Apply field-level access rules and redaction before capture. Anyone with a valid handle and the inspector in that run can read the entire retained value.
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from toolsplice import ResultSession, result_tools_from_mcp
|
|
166
|
+
from toolsplice.integrations.agno import as_agno_tool
|
|
167
|
+
|
|
168
|
+
session = ResultSession()
|
|
169
|
+
try:
|
|
170
|
+
remote = result_tools_from_mcp(catalog, caller)
|
|
171
|
+
registered = session.tools(
|
|
172
|
+
[*remote, summarize],
|
|
173
|
+
forward_to={"summarize": ["rows"]},
|
|
174
|
+
)
|
|
175
|
+
agent = Agent(model=model, tools=[as_agno_tool(t) for t in registered])
|
|
176
|
+
response = await agent.arun(question)
|
|
177
|
+
finally:
|
|
178
|
+
session.close()
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Here `catalog` is a JSON tools/list catalog restricted to the tools the user can invoke. `caller` belongs to that authorized connection. `summarize` is an application tool accepting a `rows` argument. Use the LangChain adapters in the same way. In JS:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
import { ResultSession, resultToolsFromMcp } from "toolsplice";
|
|
185
|
+
import { aiTools } from "toolsplice/ai";
|
|
186
|
+
|
|
187
|
+
const session = new ResultSession();
|
|
188
|
+
try {
|
|
189
|
+
const remote = resultToolsFromMcp(catalog, caller);
|
|
190
|
+
const registered = session.tools([...remote, summarize], {
|
|
191
|
+
forwardTo: { summarize: ["rows"] },
|
|
192
|
+
});
|
|
193
|
+
const tools = Object.assign({}, ...registered.map(t => aiTools(t)));
|
|
194
|
+
const response = await generateText({
|
|
195
|
+
model, tools, prompt: question, stopWhen: stepCountIs(8),
|
|
196
|
+
prepareStep: () => ({
|
|
197
|
+
activeTools: session.availableTools(registered).map(t => t.definition.name),
|
|
198
|
+
}),
|
|
199
|
+
});
|
|
200
|
+
} finally {
|
|
201
|
+
session.close();
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
The `availableTools` and `available_tools` selectors hide the helper schemas until a reference exists. Call the selector before each model request in hosts that support dynamic tool lists. A host with a fixed tool list can register every tool once for the run.
|
|
206
|
+
|
|
207
|
+
- `inspect_result` takes a ref and optional RFC 6901 path. Use `keys: true` to list object keys, `fields` to select object columns, `where: {field, equals}` to filter rows, and `contains` to find a literal text passage. Original row indices work as pointer segments. Offsets in text count Unicode code points. Continue with the returned `nextOffset`. A preview is a sample; retrieve exact values with a narrower selection.
|
|
208
|
+
- `call_with_result` is added only for configured destination tools and argument names. Provide `tool`, `argument`, `ref`, optional source `path`, and any other literal `arguments`. The runtime resolves the exact value, checks the destination’s schema, and calls it once. Independent calls may be submitted together by the agent host.
|
|
209
|
+
- For a destination requiring approval or a restriction on where its data comes from, supply an application callback via `authorizeForward` or `authorize_forward`. It receives the source tool name (null for manual captures), destination tool and argument, source path, and a detached copy of the resolved arguments. Only a literal true decision permits dispatch. Apply the same application authorization to normal direct tool calls. Reference forwarding calls the destination inside the application, so framework hooks attached only to the direct destination do not run on that path.
|
|
210
|
+
- The defaults are 2,048 inline bytes, 32 retained results and 8 MiB of retained serialized JSON per session. Individual results also obey the SDK’s 5 MiB JSON limit. Inspections return at most 8 KiB of JSON. The store rejects a new result when its capacity is exhausted and retains earlier handles. A provider may have finished before retention fails. Close discards references and prevents further dispatch. An already-started external side effect cannot be reversed by closing.
|
|
211
|
+
- No database, shared volume or model key is needed by the library. Keep all steps for a run on the same worker. Saved learning data, recordings and database backends have separate lifetimes. Use explicit projections at the source when your agent only needs a known small field.
|
|
212
|
+
|
|
213
|
+
### Choose a read by result size
|
|
214
|
+
|
|
215
|
+
Supply the current question once when registering tools for a run. The adaptive reader calls each provider with its native arguments and measures the returned JSON locally.
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
const registered = session.tools(tools, { adaptiveRead: question });
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
registered = session.tools(tools, adaptive_read=question)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The default passes up to 2,048 UTF-8 JSON bytes through in their original shape. For larger reads, Toolsplice looks for field names, quoted text, named rows and requested first or last search hits. It can find requested fields inside JSON-encoded files. For Markdown heading requests, it checks for a single-`#` heading outside fenced code within the first 64 KiB.
|
|
226
|
+
|
|
227
|
+
A selected result has `{ref, partial: true, selection}`. Its view is limited to 4 KiB. Inspect its opaque `result_…` handle to retrieve more from the same response. The reference can resolve the full provider value. With a default session, Toolsplice may instead return all the evidence directly for inputs up to 32 KiB. For a uniform table it can return `{complete: true, columns, rows, coverage}` when that representation contains every original cell and fits in the original byte count. Reconstruct each record by pairing the column names with its row of values. An ambiguous affordable result can also pass through as native JSON. Both paths consume zero retained handles.
|
|
228
|
+
|
|
229
|
+
`allDistinctValues` covers the full returned column whenever present. `rowsContainingText` counts records containing a literal question term in any string cell, including undisplayed text. The scan omits counts if it exceeds its limits or encounters nested data. For an explicit request such as `names containing "Campground" (case-insensitive)`, the reader can report `fieldTextMatches` with the exact field, literal, case policy, rows scanned and count. It includes `allMatchingValues` only when every matching value fits. A match in a description cannot inflate a count on the name field. These facts describe the returned array. An upstream cursor can indicate further pages. A request for refrigerated items, for example, may need a category field or a source-specific definition of refrigerated.
|
|
230
|
+
|
|
231
|
+
Set `adaptiveFallbackBytes` or `adaptive_fallback_bytes` to control the maximum source size eligible for a complete fallback. Passing an explicit `inlineBytes` or `inline_bytes` retains that inline boundary unless you also enable fallback. The inspector becomes available after a result is retained. The provider still receives one native call and bills for its own work.
|
|
232
|
+
|
|
233
|
+
### Return exact IDs or counts
|
|
234
|
+
|
|
235
|
+
Use `queryRows` or `query_rows` when your application knows the source column and output shape. This scans every supplied row once, compares typed values and preserves source order and duplicates. An empty successful source or a valid filter with no matches yields a count of zero and an empty projection. A malformed row or missing column raises an error. Fetch the required source pages before making a statement about the entire upstream collection.
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
import { queryRows } from "toolsplice";
|
|
239
|
+
|
|
240
|
+
const rows = await readManifest.execute({});
|
|
241
|
+
const { values: codes } = queryRows(rows, {
|
|
242
|
+
where: { field: "category", equals: category },
|
|
243
|
+
values: "code",
|
|
244
|
+
});
|
|
245
|
+
return { codes };
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
from toolsplice import query_rows
|
|
250
|
+
|
|
251
|
+
rows = await read_manifest.execute({})
|
|
252
|
+
result = query_rows(rows, {
|
|
253
|
+
"where": {"field": "category", "equals": category},
|
|
254
|
+
"values": "code",
|
|
255
|
+
})
|
|
256
|
+
return {"codes": result["values"]}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
The optional predicate accepts one of `equals`, `notEquals` or `contains`. For case-insensitive substring matching, use `{"field": "note", "contains": term, "caseSensitive": false}`. Omit `values` to return only `{"count": N}`. Bind the allowed fields in an application-owned tool and give each model-facing argument a description that identifies its source column.
|
|
260
|
+
|
|
261
|
+
### Keep citation URLs and budget the final model step
|
|
262
|
+
|
|
263
|
+
If a tool receives one unambiguous HTTP(S) address through `url`, `sourceUrl`, `source_url` or `uri` and returns text or a document with text, HTML or Markdown, adaptive mode returns the submitted string in `requestedUrl`. It captures the argument before calling the provider, including its escaping, query and fragment. Small pages use `{requestedUrl, value}`. For large citation reads, a selected view can include the requested heading and explicit scalar `metadata.<key>` fields. Inspect the original response by its reference when other fields are needed. A provider error still fails the read. This works with the existing adaptive registration.
|
|
264
|
+
|
|
265
|
+
In a host that controls its model loop, pass the remaining number of model requests to `session.availableTools(tools, {remainingTurns})` or `session.available_tools(tools, remaining_turns=remaining)`. Include the current request in that number. At one remaining request the catalog is empty. Ask the model to return the answer supported by the observed data and identify missing evidence. The host owns the turn count. A provider outage can still prevent a complete answer.
|
|
266
|
+
|
|
267
|
+
### Query every page before reporting an empty result
|
|
268
|
+
|
|
269
|
+
For a cursor-based API, pass a page reader to `queryRowPages` or `query_row_pages`. It receives the first-page cursor as `undefined` in JavaScript or `None` in Python. Return `{rows, nextCursor}` from each read. Omit the cursor or return null on the last page. An empty page with a continuation still advances.
|
|
270
|
+
|
|
271
|
+
```js
|
|
272
|
+
import { queryRowPages } from "toolsplice";
|
|
273
|
+
|
|
274
|
+
const result = await queryRowPages(async (cursor, signal) => {
|
|
275
|
+
const page = await listTickets.execute(cursor === undefined ? {} : { cursor }, { signal });
|
|
276
|
+
return { rows: page.tickets, nextCursor: page.nextCursor };
|
|
277
|
+
}, { where: { field: "phase", equals: "open" }, values: "id" });
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
from toolsplice import query_row_pages
|
|
282
|
+
|
|
283
|
+
async def read(cursor):
|
|
284
|
+
page = await list_tickets.execute({} if cursor is None else {"cursor": cursor})
|
|
285
|
+
return {"rows": page["tickets"], "nextCursor": page.get("nextCursor")}
|
|
286
|
+
|
|
287
|
+
result = await query_row_pages(read, {"where": {"field": "phase", "equals": "open"}, "values": "id"})
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Results preserve provider order and duplicate values. Each query allows 32 pages and 5 MiB of serialized row arrays in total by default. Set `maxPages` and `maxBytes` in JavaScript, or `max_pages` and `max_bytes` in Python, to adjust the limits. Provider errors, repeated cursors, missing columns and exceeded limits fail the query. The reported count covers the pages the server returned. Use the provider's snapshot or stable ordering when the collection can change between reads.
|
|
291
|
+
|
|
292
|
+
### Return exactly the fields a caller needs
|
|
293
|
+
|
|
294
|
+
When a scrape redirects, the page may contain a canonical URL that differs from the URL your agent was asked to cite. A projector can keep the actual request URL alongside values taken from the successful response. The agent can still choose its search query and which tool to call next.
|
|
295
|
+
|
|
296
|
+
```js
|
|
297
|
+
import { projectTool } from "toolsplice";
|
|
298
|
+
|
|
299
|
+
const cite = projectTool(
|
|
300
|
+
scrapeTool,
|
|
301
|
+
(page, args) => ({ url: args.url, revision: page.metadata.git_commit_id }),
|
|
302
|
+
{
|
|
303
|
+
description: "Scrape the requested URL and return its exact URL and Git revision.",
|
|
304
|
+
outputSchema: {
|
|
305
|
+
type: "object",
|
|
306
|
+
properties: { url: { type: "string" }, revision: { type: "string" } },
|
|
307
|
+
required: ["url", "revision"],
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
);
|
|
311
|
+
const tools = session.tools([searchTool, cite], { adaptiveRead: question });
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
```python
|
|
315
|
+
from toolsplice import project_tool
|
|
316
|
+
|
|
317
|
+
cite = project_tool(
|
|
318
|
+
scrape_tool,
|
|
319
|
+
lambda page, args: {"url": args["url"], "revision": page["metadata"]["git_commit_id"]},
|
|
320
|
+
description="Scrape the requested URL and return its exact URL and Git revision.",
|
|
321
|
+
output_schema={
|
|
322
|
+
"type": "object",
|
|
323
|
+
"properties": {"url": {"type": "string"}, "revision": {"type": "string"}},
|
|
324
|
+
"required": ["url", "revision"],
|
|
325
|
+
},
|
|
326
|
+
)
|
|
327
|
+
tools = session.tools([search_tool, cite], adaptive_read=question)
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
The wrapper calls the original tool once with its original execution options. The synchronous or asynchronous callback receives the decoded result and a snapshot of the submitted arguments. Treat the result as read-only. The wrapper retains the source tool name, input contract and annotations. Supply an output schema to validate the new shape. An upstream failure skips the callback. A projection failure reports that the tool already completed. Choose the projected fields for the particular task because subsequent inspection can only see those fields.
|
|
331
|
+
|
|
332
|
+
### Share a concurrent upstream read
|
|
333
|
+
|
|
334
|
+
Create one wrapper for each authorized provider and run. Wrap the caller before passing it to a prepared splice or an MCP result tool.
|
|
335
|
+
|
|
336
|
+
```ts
|
|
337
|
+
import { coalesceReads } from "toolsplice";
|
|
338
|
+
|
|
339
|
+
const readRegistry = coalesceReads(registryCaller, { tools: ["searchGitHub"] });
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
```python
|
|
343
|
+
from toolsplice import coalesce_reads
|
|
344
|
+
|
|
345
|
+
read_registry = coalesce_reads(registry_caller, tools=["searchGitHub"])
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
Concurrent calls with the same tool and JSON arguments share one upstream response. Each waiter receives a detached value. The next call after success or failure fetches again. Choose read-only operations whose results are interchangeable for that caller. Requests with extra metadata or per-call timeouts, cancellation signals or progress callbacks follow their own execution paths. In Python cancelling one waiting task preserves the read for other waiters. By default, at most 64 distinct reads can be shared at once. Additional distinct reads run independently.
|
|
349
|
+
|
|
350
|
+
### Read and select in one call
|
|
351
|
+
|
|
352
|
+
Enable `selectOnRead` (Python `select_on_read`) for named tools that return large results. The agent can then supply a selector with its first read. For example, if `read_report` returns an object with a `narrative` field:
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
const [read] = session.tools([readReport], { selectOnRead: ["read_report"] });
|
|
356
|
+
const page = await read.execute({
|
|
357
|
+
report_id: "night-shift",
|
|
358
|
+
select: { path: "/narrative", contains: "Inspection seal: ", limit: 64 },
|
|
359
|
+
});
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
```python
|
|
363
|
+
read, inspect_result = session.tools([read_report], select_on_read=["read_report"])
|
|
364
|
+
page = await read.execute({
|
|
365
|
+
"report_id": "night-shift",
|
|
366
|
+
"select": {"path": "/narrative", "contains": "Inspection seal: ", "limit": 64},
|
|
367
|
+
})
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Toolsplice sends the provider its original arguments and applies `select` to the returned JSON. A native filter can reduce the provider payload before selection. Omit `path` when the native arguments already produce the target text or array. A selected read retains the whole result, even if small. Use the returned `ref` to change fields, page the result or perform an authorized handoff without re-fetching. If a literal is absent, the response includes `found: false`. If the selected path is missing or the result type is incompatible, the response includes a `selectionError` and the same reusable reference.
|
|
371
|
+
|
|
372
|
+
The schema extension accepts simple root object schemas. For a tool with its own `select` argument or a composed root schema, use `session.readAndSelect(tool, providerArgs, selection)` or `await session.read_and_select(tool, provider_args, selection)`. The selected view limits what enters the model context. Apply authorization and redaction before calling the tool because the full result is available within the session.
|
|
373
|
+
|
|
374
|
+
## Resume an agent tool after the worker exits
|
|
375
|
+
|
|
376
|
+
Put a page job inside the tool handler. The queue worker can call the same handler directly on redelivery. Open the checkpoint store once at worker startup. Bind `jobId`, the authorized data source, tenant and snapshot to the job on your server. The example ranks earthquake magnitude types and includes ties for second place.
|
|
377
|
+
|
|
378
|
+
### Vercel AI SDK
|
|
379
|
+
|
|
380
|
+
```js
|
|
381
|
+
import { generateText, tool, jsonSchema } from "ai";
|
|
382
|
+
import { rowPageJob } from "toolsplice";
|
|
383
|
+
|
|
384
|
+
const pages = rowPageJob(
|
|
385
|
+
{ groupBy: { field: "magnitude_type", top: 2, ties: "include" } },
|
|
386
|
+
{ checkpoint: { store, jobId, context: { tenant, snapshot } } },
|
|
387
|
+
);
|
|
388
|
+
const runPages = () => pages.run(({ cursor, key }) => source.readPage({ cursor, key }));
|
|
389
|
+
const getEvents = tool({
|
|
390
|
+
description: "Rank earthquake magnitude types for the current snapshot.",
|
|
391
|
+
inputSchema: jsonSchema({ type: "object", properties: {}, additionalProperties: false }),
|
|
392
|
+
execute: runPages,
|
|
393
|
+
});
|
|
394
|
+
const turn = await generateText({
|
|
395
|
+
model, prompt: question, tools: { get_events: getEvents },
|
|
396
|
+
toolChoice: { type: "tool", toolName: "get_events" },
|
|
397
|
+
});
|
|
398
|
+
const outcome = turn.toolResults[0].output;
|
|
399
|
+
// On queue redelivery, reconstruct pages and call await runPages().
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Agno
|
|
403
|
+
|
|
404
|
+
```python
|
|
405
|
+
from agno.tools.function import Function
|
|
406
|
+
from agno.agent import Agent
|
|
407
|
+
from toolsplice import row_page_job
|
|
408
|
+
|
|
409
|
+
pages = row_page_job(
|
|
410
|
+
{"groupBy": {"field": "magnitude_type", "top": 2, "ties": "include"}},
|
|
411
|
+
checkpoint={"store": store, "job_id": job_id,
|
|
412
|
+
"context": {"tenant": tenant, "snapshot": snapshot}},
|
|
413
|
+
)
|
|
414
|
+
|
|
415
|
+
async def get_events() -> dict:
|
|
416
|
+
"""Rank earthquake magnitude types for the current snapshot."""
|
|
417
|
+
return await pages.run(lambda a: source.read_page(cursor=a["cursor"], key=a["key"]))
|
|
418
|
+
|
|
419
|
+
events_tool = Function.from_callable(get_events)
|
|
420
|
+
events_tool.stop_after_tool_call = True
|
|
421
|
+
reply = await Agent(model=model, tools=[events_tool], tool_choice="required").arun(question)
|
|
422
|
+
# On queue redelivery, reconstruct pages and call await get_events().
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Your source adapter returns `{rows, nextCursor}` and can persist its actual response under the attempt key. A completed job returns `result`. A deferred job supplies `retryAt` in Unix milliseconds so the queue can release the worker until then. When the model chooses the query, save that selection before calling the source. Two replacement workers can reuse that selection and compete for the next page. See the examples for [saving the selection and reconciling an interrupted read](INTEGRATION-QUICKSTART.md#inspect-and-recover-one-page).
|
|
426
|
+
|
|
427
|
+
## Other frameworks and tests
|
|
428
|
+
|
|
429
|
+
Use `await workflow.execute(arguments, **run_options)` in Python or `await workflow.execute(args, options)` in JavaScript from an async tool handler. A workflow failure raises an error with the stage and completed target count when available. A destination may have run before a failure. The separate `call` handler returns an MCP envelope for applications that speak MCP directly.
|
|
430
|
+
|
|
431
|
+
The source checkout includes offline adapter checks and live agent loops in `bench/frameworks/`. The live checks use each framework’s own OpenAI provider, a native MCP connection and a local query builder. They check the tool result and the final JSON answer separately.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Toolsplice benchmark results
|
|
2
|
+
|
|
3
|
+
These measurements cover two decisions developers can make independently. A tool can return a complete answer directly, and a worker can save that answer or its page progress for another worker. The native comparisons below include both a conventional agent loop and a hand-written early return.
|
|
4
|
+
|
|
5
|
+
## Returning a complete answer
|
|
6
|
+
|
|
7
|
+
On November 25, 2026, Vercel AI SDK and Agno ran two live MCP tasks on one Mac using GPT-6 Luna. Each row is 20 fresh jobs. Microsoft Learn searched for a page, followed the exact result URL and reported its heading and literal count. Hugging Face read three fields from the Whisper Tiny configuration. Each arm used the same application tool and prompt for its task.
|
|
8
|
+
|
|
9
|
+
| Framework | Live MCP | Implementation | Exact answers | Model calls/job | MCP reads/job | p95 seconds | Mean model USD/job |
|
|
10
|
+
| --- | --- | --- | ---: | ---: | ---: | ---: | ---: |
|
|
11
|
+
| Vercel AI SDK | Microsoft Learn | Native agent loop | 20/20 | 2 | 2 | 6.379 | 0.0000680 |
|
|
12
|
+
| Vercel AI SDK | Microsoft Learn | Native early return | 20/20 | 1 | 2 | 4.491 | 0.0000264 |
|
|
13
|
+
| Vercel AI SDK | Microsoft Learn | Toolsplice checkpoint | 20/20 | 1 | 2 | 4.039 | 0.0000264 |
|
|
14
|
+
| Agno | Microsoft Learn | Native agent loop | 20/20 | 2 | 2 | 7.892 | 0.0000680 |
|
|
15
|
+
| Agno | Microsoft Learn | Native early return | 20/20 | 1 | 2 | 5.912 | 0.0000264 |
|
|
16
|
+
| Agno | Microsoft Learn | Toolsplice checkpoint | 20/20 | 1 | 2 | 4.988 | 0.0000264 |
|
|
17
|
+
| Vercel AI SDK | Hugging Face | Native agent loop | 20/20 | 2 | 1 | 3.938 | 0.0000504 |
|
|
18
|
+
| Vercel AI SDK | Hugging Face | Native early return | 20/20 | 1 | 1 | 2.233 | 0.0000236 |
|
|
19
|
+
| Vercel AI SDK | Hugging Face | Toolsplice checkpoint | 20/20 | 1 | 1 | 2.233 | 0.0000236 |
|
|
20
|
+
| Agno | Hugging Face | Native agent loop | 20/20 | 2 | 1 | 3.996 | 0.0000504 |
|
|
21
|
+
| Agno | Hugging Face | Native early return | 20/20 | 1 | 1 | 3.801 | 0.0000236 |
|
|
22
|
+
| Agno | Hugging Face | Toolsplice checkpoint | 20/20 | 1 | 1 | 2.839 | 0.0000236 |
|
|
23
|
+
|
|
24
|
+
Both early-return implementations saved one model call and had identical token costs. Toolsplice also persisted the validated answer. In four additional jobs we killed the writer after the save returned. A fresh process in either language recovered each answer with zero extra model or MCP calls. A crash before the first successful save requires reconciliation.
|
|
25
|
+
|
|
26
|
+
Each job used a fresh connection and job ID. The arms rotated within each task. Timing includes client initialization, model requests, reads, checkpoint I/O and connection closure. p95 is the nineteenth sorted time out of twenty. The four cohorts ran concurrently. Cost uses recorded model usage and the benchmark's USD rates per million tokens ($0.10 input and $0.50 output). No input tokens were cached in these runs. Billing statements, MCP fees and infrastructure costs were outside the measurement.
|
|
27
|
+
|
|
28
|
+
## Resuming a ten-page read
|
|
29
|
+
|
|
30
|
+
On November 30, 2026, local Vercel AI SDK 6.0.339 and Agno 3.2.1 workers grouped 20 historical earthquake events, including a tie for second place. The harness paced the live source, throttled before page eight, killed the writer after the throttle was recorded and let a JavaScript and a Python worker compete to resume. The native implementation had its own durable checkpoint. Both arms kept the original job ID. [Public earthquake MCP](https://earthquake.caseyjhand.com/)
|
|
31
|
+
|
|
32
|
+
| Writer | Implementation | Exact answers | Model calls/job | MCP reads/job | Worker p95 seconds | Wall p95 seconds | Mean model USD/job |
|
|
33
|
+
| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: |
|
|
34
|
+
| Vercel AI SDK | Native checkpoint | 4/4 | 1 | 10 | 27.33 | 27.57 | 0.0000168 |
|
|
35
|
+
| Vercel AI SDK | Toolsplice | 4/4 | 1 | 10 | 24.84 | 25.08 | 0.0000168 |
|
|
36
|
+
| Agno | Native checkpoint | 4/4 | 1 | 10 | 24.20 | 24.44 | 0.0000168 |
|
|
37
|
+
| Agno | Toolsplice | 4/4 | 1 | 10 | 25.27 | 25.50 | 0.0000168 |
|
|
38
|
+
|
|
39
|
+
Worker time sums the time occupied by the three workers. Wall time includes queue redelivery. Worker startup and terminal verification were timed separately. Every job returned the expected groups and page order. With four repetitions on one task, p95 is the maximum observed time. An earlier 20-pair comparison per framework had a paired 95% bootstrap interval spanning zero for both wall-time differences. These results support recovery with equal call counts. Relative latency on a different application needs its own measurement.
|
|
40
|
+
|
|
41
|
+
## Measure your workload
|
|
42
|
+
|
|
43
|
+
Generate a calibration driver with `npx toolsplice evaluate --init routes.mjs` or `toolsplice evaluate --init routes.py`. Replace its sample tasks, agent runner and grader. Give each arm the same inputs, include a native early-return baseline where possible, and keep separate fit and holdout cases. Record model calls, exact-answer checks and provider usage. Run `evaluate --driver routes.mjs --plan` to inspect the number of trials before starting paid work. [Calibration and diagnostics](INTEGRATION-QUICKSTART.md#choose-a-route-with-your-own-tasks)
|