Skip to content

Commit b2bf02b

Browse files
committed
Add agent-native MCP layer and tinybench benchmarks
1 parent 300c3a4 commit b2bf02b

24 files changed

Lines changed: 679 additions & 10 deletions

README.MD

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,30 @@ This repository includes GitHub Actions workflows:
103103
- `ci.yml`: runs install, build, tests, and coverage on push/PR.
104104
- `release.yml`: runs release checks and can publish to npm on version tags (`v*`) when `NPM_TOKEN` is configured.
105105

106+
## Agent-Native Mode
107+
108+
Qirrel ships with an agent-native bridge plus an MCP server so the same parsing core works for API code and agent toolchains.
109+
110+
```ts
111+
import { createQirrelAgentBridge } from "qirrel";
112+
113+
const bridge = createQirrelAgentBridge();
114+
const result = await bridge.callTool("qirrel.parse_text", { text: "Email me@example.com" });
115+
console.log(result.structuredContent);
116+
```
117+
118+
Run MCP server:
119+
120+
```bash
121+
bun run mcp:start
122+
```
123+
124+
Run benchmark:
125+
126+
```bash
127+
bun run bench:agent
128+
```
129+
106130
## Documentation
107131

108132
- [Docs Home](./docs/README.md)
@@ -114,6 +138,7 @@ This repository includes GitHub Actions workflows:
114138
- [Pipeline Events](./docs/events.md)
115139
- [LLM Integration](./docs/integrations/llm.md)
116140
- [Architecture Walkthrough](./docs/walkthrough.md)
141+
- [Agent-Native Integration](./docs/agent-native.md)
117142

118143
## Contributing
119144

bench/agent-native.bench.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Bench } from "tinybench";
2+
import { processText } from "../src/api";
3+
import { createMcpRequestHandler, createQirrelAgentBridge } from "../src/agent";
4+
5+
const sampleText =
6+
"Contact support@example.com or +1 415 555 2671 and visit https://example.com";
7+
8+
async function run(): Promise<void> {
9+
const bridge = createQirrelAgentBridge();
10+
const handle = createMcpRequestHandler(bridge);
11+
const bench = new Bench({ time: 1_000, warmupTime: 300 });
12+
13+
bench.add("direct: processText()", async () => {
14+
await processText(sampleText);
15+
});
16+
17+
bench.add("agent bridge: qirrel.parse_text", async () => {
18+
await bridge.callTool("qirrel.parse_text", { text: sampleText });
19+
});
20+
21+
bench.add("mcp handler: tools/call", async () => {
22+
await handle({
23+
jsonrpc: "2.0",
24+
id: 1,
25+
method: "tools/call",
26+
params: {
27+
name: "qirrel.parse_text",
28+
arguments: { text: sampleText },
29+
},
30+
});
31+
});
32+
33+
await bench.run();
34+
35+
const rows = bench.tasks.map((task) => ({
36+
name: task.name,
37+
"ops/sec": task.result ? Math.round(task.result.hz) : 0,
38+
"avg ms": task.result ? Number(task.result.mean.toFixed(3)) : 0,
39+
"p99 ms": task.result ? Number(task.result.p99.toFixed(3)) : 0,
40+
}));
41+
42+
console.table(rows);
43+
}
44+
45+
void run();

bun.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ GitHub-first Markdown docs for Qirrel.
1313
- [Pipeline Events](./events.md)
1414
- [LLM Integration](./integrations/llm.md)
1515
- [Architecture Walkthrough](./walkthrough.md)
16+
- [Agent-Native Integration](./agent-native.md)
1617

1718
## Quick Navigation
1819

1920
- Core: [API](./api.md) | [Configuration](./configuration.md) | [Examples](./examples.md)
2021
- Usage: [Basic](./usage/basic.md) | [Caching](./usage/caching.md)
21-
- Advanced: [Events](./events.md) | [LLM](./integrations/llm.md) | [Architecture](./walkthrough.md)
22+
- Advanced: [Events](./events.md) | [LLM](./integrations/llm.md) | [Architecture](./walkthrough.md) | [Agent-Native](./agent-native.md)

docs/agent-native.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Agent-Native Integration
2+
3+
[Docs Home](./README.md) | [API](./api.md) | [Configuration](./configuration.md) | [Examples](./examples.md) | [Basic](./usage/basic.md) | [Caching](./usage/caching.md) | [Events](./events.md) | [LLM](./integrations/llm.md) | [Architecture](./walkthrough.md)
4+
5+
Qirrel now includes an agent-native layer with:
6+
7+
- a reusable `AgentBridge` abstraction
8+
- built-in Qirrel tools (`qirrel.parse_text`, `qirrel.parse_batch`)
9+
- a lightweight MCP JSON-RPC server (`qirrel-mcp`)
10+
- tinybench benchmarks for direct vs agent-mode overhead
11+
12+
## Core Idea
13+
14+
Use one structure for both classic API calls and agent tools:
15+
16+
- Regular function: `processText(text)`
17+
- Agent tool: `qirrel.parse_text({ text })`
18+
19+
`AgentBridge.registerApiTool(...)` adapts non-agent-native handlers into MCP-style tool results with both:
20+
21+
- `content` (agent-readable text)
22+
- `structuredContent` (machine-usable JSON)
23+
24+
## Use the Built-In Bridge
25+
26+
```ts
27+
import { createQirrelAgentBridge } from "qirrel";
28+
29+
const bridge = createQirrelAgentBridge();
30+
const result = await bridge.callTool("qirrel.parse_text", {
31+
text: "Email hello@example.com",
32+
});
33+
34+
console.log(result.structuredContent);
35+
```
36+
37+
## Wrap Your Existing APIs
38+
39+
```ts
40+
import { AgentBridge } from "qirrel";
41+
42+
const bridge = new AgentBridge();
43+
44+
bridge.registerApiTool(
45+
{
46+
name: "inventory.lookup",
47+
description: "Lookup stock by SKU",
48+
inputSchema: {
49+
type: "object",
50+
properties: { sku: { type: "string" } },
51+
required: ["sku"],
52+
},
53+
},
54+
async ({ sku }: { sku: string }) => {
55+
return { sku, inStock: true };
56+
},
57+
);
58+
```
59+
60+
## Start MCP Server (stdio)
61+
62+
```bash
63+
bun run mcp:start
64+
```
65+
66+
Or after install:
67+
68+
```bash
69+
qirrel-mcp
70+
```
71+
72+
## Benchmark Agent Overhead
73+
74+
```bash
75+
bun run bench:agent
76+
```
77+
78+
This compares:
79+
80+
- direct API (`processText`)
81+
- tool call via `AgentBridge`
82+
- MCP `tools/call` request handler path

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# API Reference
22

3-
[Docs Home](./README.md) | [Configuration](./configuration.md) | [Examples](./examples.md) | [Basic](./usage/basic.md) | [Caching](./usage/caching.md) | [Events](./events.md) | [LLM](./integrations/llm.md) | [Architecture](./walkthrough.md)
3+
[Docs Home](./README.md) | [Configuration](./configuration.md) | [Examples](./examples.md) | [Basic](./usage/basic.md) | [Caching](./usage/caching.md) | [Events](./events.md) | [LLM](./integrations/llm.md) | [Architecture](./walkthrough.md) | [Agent-Native](./agent-native.md)
44

55
## Top-Level Functions
66

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Configuration Guide
22

3-
[Docs Home](./README.md) | [API](./api.md) | [Examples](./examples.md) | [Basic](./usage/basic.md) | [Caching](./usage/caching.md) | [Events](./events.md) | [LLM](./integrations/llm.md) | [Architecture](./walkthrough.md)
3+
[Docs Home](./README.md) | [API](./api.md) | [Examples](./examples.md) | [Basic](./usage/basic.md) | [Caching](./usage/caching.md) | [Events](./events.md) | [LLM](./integrations/llm.md) | [Architecture](./walkthrough.md) | [Agent-Native](./agent-native.md)
44

55
Qirrel loads config in this order:
66

docs/events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Pipeline Events
22

3-
[Docs Home](./README.md) | [API](./api.md) | [Configuration](./configuration.md) | [Examples](./examples.md) | [Basic](./usage/basic.md) | [Caching](./usage/caching.md) | [LLM](./integrations/llm.md) | [Architecture](./walkthrough.md)
3+
[Docs Home](./README.md) | [API](./api.md) | [Configuration](./configuration.md) | [Examples](./examples.md) | [Basic](./usage/basic.md) | [Caching](./usage/caching.md) | [LLM](./integrations/llm.md) | [Architecture](./walkthrough.md) | [Agent-Native](./agent-native.md)
44

55
Qirrel exposes lifecycle events on `Pipeline` so you can monitor execution, collect metrics, and handle failures without modifying core processors.
66

docs/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Usage Examples
22

3-
[Docs Home](./README.md) | [API](./api.md) | [Configuration](./configuration.md) | [Basic](./usage/basic.md) | [Caching](./usage/caching.md) | [Events](./events.md) | [LLM](./integrations/llm.md) | [Architecture](./walkthrough.md)
3+
[Docs Home](./README.md) | [API](./api.md) | [Configuration](./configuration.md) | [Basic](./usage/basic.md) | [Caching](./usage/caching.md) | [Events](./events.md) | [LLM](./integrations/llm.md) | [Architecture](./walkthrough.md) | [Agent-Native](./agent-native.md)
44

55
## Single Input
66

docs/integrations/llm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LLM Integration
22

3-
[Docs Home](../README.md) | [API](../api.md) | [Configuration](../configuration.md) | [Examples](../examples.md) | [Basic](../usage/basic.md) | [Caching](../usage/caching.md) | [Events](../events.md) | [Architecture](../walkthrough.md)
3+
[Docs Home](../README.md) | [API](../api.md) | [Configuration](../configuration.md) | [Examples](../examples.md) | [Basic](../usage/basic.md) | [Caching](../usage/caching.md) | [Events](../events.md) | [Architecture](../walkthrough.md) | [Agent-Native](../agent-native.md)
44

55
Qirrel supports pluggable LLM adapters (`gemini`, `openai`, and generic OpenAI-compatible endpoints).
66

0 commit comments

Comments
 (0)