|
| 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 |
0 commit comments