@thoughtflow/core 0.2.1 → 0.3.1
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 +284 -225
- package/dist/adapters/llm/openai.adapter.js +4 -4
- package/dist/adapters/llm/openai.adapter.js.map +1 -1
- package/dist/bin/mcp-server.d.ts +18 -0
- package/dist/bin/mcp-server.d.ts.map +1 -0
- package/dist/bin/mcp-server.js +272 -0
- package/dist/bin/mcp-server.js.map +1 -0
- package/dist/contracts/mcp.types.d.ts +8 -1
- package/dist/contracts/mcp.types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/libs/mcp/mcp-llm-caller.class.d.ts +35 -0
- package/dist/libs/mcp/mcp-llm-caller.class.d.ts.map +1 -0
- package/dist/libs/mcp/mcp-llm-caller.class.js +31 -0
- package/dist/libs/mcp/mcp-llm-caller.class.js.map +1 -0
- package/dist/libs/mcp/mcp-server.class.d.ts +5 -5
- package/dist/libs/mcp/mcp-server.class.d.ts.map +1 -1
- package/dist/libs/mcp/mcp-server.class.js +52 -106
- package/dist/libs/mcp/mcp-server.class.js.map +1 -1
- package/dist/libs/mcp/mcp-tool-registry.class.js +1 -1
- package/dist/libs/mcp/mcp-tool-registry.class.js.map +1 -1
- package/dist/libs/mcp/vision-adapter-resolver.d.ts +15 -0
- package/dist/libs/mcp/vision-adapter-resolver.d.ts.map +1 -0
- package/dist/libs/mcp/vision-adapter-resolver.js +48 -0
- package/dist/libs/mcp/vision-adapter-resolver.js.map +1 -0
- package/dist/tools/mcp/tool-search.tool.d.ts +35 -0
- package/dist/tools/mcp/tool-search.tool.d.ts.map +1 -0
- package/dist/tools/mcp/tool-search.tool.js +186 -0
- package/dist/tools/mcp/tool-search.tool.js.map +1 -0
- package/dist/tools/workspace/browser-session-pool.d.ts +88 -0
- package/dist/tools/workspace/browser-session-pool.d.ts.map +1 -0
- package/dist/tools/workspace/browser-session-pool.js +302 -0
- package/dist/tools/workspace/browser-session-pool.js.map +1 -0
- package/package.json +5 -1
- package/skills/thoughtflow-mcp/SKILL.md +294 -0
package/README.md
CHANGED
|
@@ -1,326 +1,386 @@
|
|
|
1
1
|
# thoughtflow
|
|
2
2
|
|
|
3
|
-
**TypeScript framework for building autonomous AI agents** —
|
|
3
|
+
**TypeScript framework for building autonomous AI agents** — streaming, tool-calling, plugins, skills, workspace automation, and advanced orchestration.
|
|
4
4
|
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://www.npmjs.com/package/@thoughtflow/core)
|
|
7
7
|
|
|
8
8
|
```ts
|
|
9
|
-
import { Conversation, OpenAiAdapter } from "
|
|
9
|
+
import { Conversation, OpenAiAdapter } from "thoughtflow";
|
|
10
10
|
|
|
11
11
|
const agent = new Conversation({
|
|
12
12
|
llmAdapter: new OpenAiAdapter({ apiKey: process.env.OPENAI_API_KEY }),
|
|
13
13
|
model: "gpt-4o",
|
|
14
|
-
systemPrompt: "You are a helpful
|
|
14
|
+
systemPrompt: "You are a helpful agent with tools.",
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
const { output } = await agent.sendPrompt("
|
|
17
|
+
const { output } = await agent.sendPrompt("What files are in the project?");
|
|
18
18
|
console.log(output);
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Features
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
- **Conversation loop** — multi-turn agent with streaming, tool-calling, and interrupt support
|
|
26
|
+
- **Adapter system** — OpenAI, Anthropic, Ollama, vLLM, and mock adapters via `AdapterFactory`
|
|
27
|
+
- **120+ built-in tools** — file read/write, search, git, browser, docker, code analysis, refactoring, testing, planning, memory, and more
|
|
28
|
+
- **Context window management** — sliding-window and truncation strategies to stay within model limits
|
|
29
|
+
- **Subagent orchestration** — spawn child agents with isolated context, tools, and state
|
|
30
|
+
- **Plugins** — workspace, docker, browser, codebase intelligence
|
|
31
|
+
- **Skills** — loadable `.md` instructions that inject context and constraints
|
|
32
|
+
- **Storage abstraction** — in-memory, JSON file, LanceDB vector store, Ollama/Transformers embeddings
|
|
33
|
+
- **Event bus** — RxJS-based streaming events for real-time UI or logging
|
|
34
|
+
- **Task flow engine** — multi-stage pipelines with git commit/push, docker, and phase gates
|
|
35
|
+
- **MCP support** — Model Context Protocol server with smart compressed tool list, `tool_search` for on-demand schema discovery, multi-provider routing, and vision browser
|
|
27
36
|
|
|
28
|
-
|
|
37
|
+
## Quickstart
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
- **Observability over opacity.** Tool calls are events you subscribe to. Iteration counts,
|
|
33
|
-
token usage, stall detection — all exposed. Nothing is hidden behind a magic decorator.
|
|
34
|
-
- **Verification over trust.** The framework doesn't assume an LLM's output is correct.
|
|
35
|
-
Subagents report what they *did*, not what they *said*. You decide when to trust.
|
|
36
|
-
- **Explicit composition.** Agents are assembled from visible parts: adapter, model, tool list,
|
|
37
|
-
system prompt, skills, temperature, iteration limits, callbacks. Every knob is on the surface.
|
|
38
|
-
- **Autonomy with bounds.** Agents can be autonomous — but bounded by explicit tool sets,
|
|
39
|
-
skill definitions, iteration caps, stall detection, and human-in-the-loop interrupts.
|
|
40
|
-
|
|
41
|
-
> thoughtflow emerged from building production agent systems where "it mostly works"
|
|
42
|
-
> wasn't enough. When an agent misbehaves in production, you need to know *why* —
|
|
43
|
-
> not dig through three layers of abstraction to find the actual prompt that was sent.
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
## Installation
|
|
39
|
+
### Installation
|
|
48
40
|
|
|
49
41
|
```bash
|
|
50
|
-
npm install
|
|
42
|
+
npm install thoughtflow
|
|
51
43
|
# or
|
|
52
|
-
bun add
|
|
44
|
+
bun add thoughtflow
|
|
53
45
|
```
|
|
54
46
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
> Designed for self-hosted LLMs — tested with **Qwen 3.6** and **Ornith 1.0-35B** inference on vLLM, Ollama, and OpenAI-compatible endpoints. The adapter pattern makes it trivial to point at any local or cloud provider.
|
|
58
|
-
|
|
59
|
-
### Sub-packages
|
|
60
|
-
|
|
61
|
-
Additional functionality is available in separate packages for specific use cases:
|
|
62
|
-
|
|
63
|
-
| Package | What it adds | Dependencies |
|
|
64
|
-
|---------|-------------|--------------|
|
|
65
|
-
| `@thoughtflow/codebase` | Code analysis, quality metrics, neural tools, contexts | ast-grep, better-sqlite3 |
|
|
66
|
-
| `@thoughtflow/browser` | Playwright-based browser automation | playwright |
|
|
67
|
-
| `@thoughtflow/vector` | Vector stores (LanceDB) + local embeddings (Hugging Face) | lancedb, transformers |
|
|
68
|
-
| `@thoughtflow/decoder` | TypeScript structural decoder (ts-morph) | ts-morph |
|
|
69
|
-
|
|
70
|
-
```bash
|
|
71
|
-
npm install @thoughtflow/codebase # code analysis tools
|
|
72
|
-
npm install @thoughtflow/browser # browser automation
|
|
73
|
-
npm install @thoughtflow/vector # vector search & embeddings
|
|
74
|
-
npm install @thoughtflow/decoder # TypeScript AST decoder
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Each sub-package imports the core types from `@thoughtflow/core` and adds its own tools, libs, and adapters.
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## Core concepts
|
|
82
|
-
|
|
83
|
-
### Orchestration patterns
|
|
84
|
-
|
|
85
|
-
Thoughtflow provides six distinct patterns for composing LLM agents:
|
|
86
|
-
|
|
87
|
-
| Pattern | Description | When to use |
|
|
88
|
-
|---------|-------------|-------------|
|
|
89
|
-
| **Single loop** | One `Conversation` with tools, stall detection, streaming | Simple Q&A, code generation, single tasks |
|
|
90
|
-
| **Pipeline** | Sequential agents that pass artifacts between them | Code review, document processing, staged workflows |
|
|
91
|
-
| **Subagent fan-out** | Parent delegates sub-tasks to child agents, collects verified results | Parallel research, multi-file analysis, independent tasks |
|
|
92
|
-
| **Saga** | Pipeline with compensating rollbacks on failure | Automated refactoring, deployments, irreversible operations |
|
|
93
|
-
| **Role orchestrator** | Role-based pipeline with journal tracking and artifact passing | Code review with analyst → planner → implementer → reviewer roles |
|
|
94
|
-
| **Dynamic decomposition** | Agent breaks a task into sub-problems with dependency tracking | Complex multi-step problems, cross-cutting changes |
|
|
95
|
-
|
|
96
|
-
### Verification principle
|
|
97
|
-
|
|
98
|
-
The most important design rule: **don't trust the LLM's self-reported output.**
|
|
47
|
+
### Basic usage
|
|
99
48
|
|
|
100
49
|
```ts
|
|
101
|
-
|
|
102
|
-
const result = await subagent.runTask("count files in src/");
|
|
103
|
-
// Return actual (verified) data to parent — not the LLM's self-reported version
|
|
104
|
-
return { fileCount: result.toolOutputs.fileCount };
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Every demo in this repo verifies subagent outputs against ground truth —
|
|
108
|
-
tool execution results, not LLM summaries.
|
|
50
|
+
import { Conversation, OpenAiAdapter, AdapterFactory } from "thoughtflow";
|
|
109
51
|
|
|
110
|
-
|
|
52
|
+
// Option A: direct adapter
|
|
53
|
+
const agent = new Conversation({
|
|
54
|
+
llmAdapter: new OpenAiAdapter({ apiKey: "sk-..." }),
|
|
55
|
+
model: "gpt-4o",
|
|
56
|
+
});
|
|
111
57
|
|
|
112
|
-
|
|
58
|
+
// Option B: factory with provider
|
|
59
|
+
const adapter = AdapterFactory.create({
|
|
60
|
+
provider: "openai",
|
|
61
|
+
baseUrl: "https://api.openai.com/v1",
|
|
62
|
+
apiKey: "sk-...",
|
|
63
|
+
});
|
|
113
64
|
|
|
114
|
-
|
|
65
|
+
// Multi-turn conversation
|
|
66
|
+
await agent.sendPrompt("List the files in src/");
|
|
67
|
+
const history = agent.getHistory(); // full message history
|
|
115
68
|
|
|
116
|
-
|
|
117
|
-
import {
|
|
69
|
+
// With tools
|
|
70
|
+
import { ReadFileTool, GrepTool } from "thoughtflow";
|
|
118
71
|
|
|
119
72
|
const agent = new Conversation({
|
|
120
|
-
llmAdapter:
|
|
73
|
+
llmAdapter: adapter,
|
|
121
74
|
model: "gpt-4o",
|
|
122
|
-
systemPrompt: "You are a coding assistant. Use tools to explore and modify code.",
|
|
123
75
|
tools: [
|
|
124
76
|
new ReadFileTool("/path/to/project"),
|
|
125
77
|
new GrepTool("/path/to/project"),
|
|
126
78
|
],
|
|
127
79
|
});
|
|
128
|
-
|
|
129
|
-
const { output } = await agent.sendPrompt("Find all TODO comments in src/");
|
|
130
80
|
```
|
|
131
81
|
|
|
132
|
-
###
|
|
82
|
+
### Streaming events
|
|
133
83
|
|
|
134
84
|
```ts
|
|
135
|
-
|
|
136
|
-
await agent.sendPrompt("How is the ReadFileTool implemented?");
|
|
137
|
-
const history = agent.getHistory(); // full message history
|
|
138
|
-
```
|
|
85
|
+
import { filter } from "rxjs";
|
|
139
86
|
|
|
140
|
-
### 3. Streaming events
|
|
141
|
-
|
|
142
|
-
Thoughtflow emits RxJS events for real-time UI and logging:
|
|
143
|
-
|
|
144
|
-
```ts
|
|
145
87
|
agent.events.pipe(
|
|
146
|
-
filter((e) => e.type === "
|
|
88
|
+
filter((e) => e.type === "stream:chunk"),
|
|
147
89
|
).subscribe((chunk) => {
|
|
148
|
-
process.stdout.write(chunk.
|
|
90
|
+
process.stdout.write(chunk.delta.content ?? "");
|
|
149
91
|
});
|
|
150
92
|
```
|
|
151
93
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
### 4. Using different providers
|
|
94
|
+
### Subagent delegation
|
|
155
95
|
|
|
156
96
|
```ts
|
|
157
|
-
import {
|
|
97
|
+
import { SubagentConversationTool } from "thoughtflow";
|
|
158
98
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
99
|
+
const agent = new Conversation({
|
|
100
|
+
llmAdapter: adapter,
|
|
101
|
+
model: "gpt-4o",
|
|
102
|
+
tools: [new SubagentConversationTool()],
|
|
163
103
|
});
|
|
164
104
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
105
|
+
await agent.sendPrompt(
|
|
106
|
+
"Research the best Node.js testing frameworks, then summarize."
|
|
107
|
+
);
|
|
108
|
+
```
|
|
170
109
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
110
|
+
## Architecture
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
thoughtflow/
|
|
114
|
+
├── packages/mcp-server/ # @thoughtflow/mcp-server — thin npm wrapper
|
|
115
|
+
├── src/
|
|
116
|
+
│ ├── adapters/llm/ # LLM provider adapters (OpenAI, Anthropic, Ollama, mock)
|
|
117
|
+
│ ├── bin/ # CLI entry point (mcp-server)
|
|
118
|
+
│ ├── contracts/ # TypeScript interfaces and types
|
|
119
|
+
│ ├── contexts/ # Context document management & routing
|
|
120
|
+
│ ├── libs/
|
|
121
|
+
│ │ ├── mcp/ # MCP protocol: JSON-RPC, server, tool registry
|
|
122
|
+
│ │ └── ... # Core libraries (runner, history, subagents, task flow)
|
|
123
|
+
│ ├── plugins/ # Workspace, Docker, Browser, Codebase Intelligence
|
|
124
|
+
│ ├── skills/ # Skill loader + built-in .md skill definitions
|
|
125
|
+
│ ├── storage/ # Persistence adapters (memory, JSON, vector stores)
|
|
126
|
+
│ ├── tools/
|
|
127
|
+
│ │ ├── mcp/ # tool_search — on-demand tool discovery
|
|
128
|
+
│ │ ├── workspace/ # file, git, browser, docker, terminal, vision browser
|
|
129
|
+
│ │ ├── codebase/ # search, graph, impact, knowledge, crossref
|
|
130
|
+
│ │ ├── planning/ # breakdown, deps, estimate, risks, progress
|
|
131
|
+
│ │ ├── quality/ # complexity, coupling, coverage, duplication
|
|
132
|
+
│ │ ├── refactor/ # rename, extract, split, move, imports
|
|
133
|
+
│ │ ├── testing/ # gen-unit, gen-integration, fuzz, snapshot, fix
|
|
134
|
+
│ │ ├── docs/ # gen-readme, gen-api, gen-adr, check-links
|
|
135
|
+
│ │ ├── neural/ # review, debug, explain, optimize, security
|
|
136
|
+
│ │ ├── memory/ # save, recall, context, patterns, lessons
|
|
137
|
+
│ │ ├── database/ # migration, diagram, index-suggest
|
|
138
|
+
│ │ └── devops/ # ci-diagnose, deploy-check, docker-optimize
|
|
139
|
+
│ └── quick/ # Preset configs for common setups
|
|
140
|
+
└── tests/ # 56 unit tests (MCP protocol, JSON-RPC, tool registry)
|
|
177
141
|
```
|
|
178
142
|
|
|
179
|
-
|
|
143
|
+
## LLM Providers
|
|
144
|
+
|
|
145
|
+
| Provider | Adapter | baseUrl example |
|
|
180
146
|
|----------|---------|-----------------|
|
|
181
147
|
| OpenAI-compatible | `OpenAiAdapter` | `https://api.openai.com/v1` |
|
|
182
148
|
| Anthropic | `AnthropicAdapter` | — |
|
|
183
149
|
| Ollama | `OllamaAdapter` | `http://localhost:11434` |
|
|
184
150
|
| Mock | `MockAdapter` | — (testing) |
|
|
185
151
|
|
|
186
|
-
|
|
152
|
+
```ts
|
|
153
|
+
const adapter = AdapterFactory.create({
|
|
154
|
+
provider: "ollama",
|
|
155
|
+
baseUrl: "http://localhost:11434",
|
|
156
|
+
});
|
|
157
|
+
// Adapter appends /v1/chat internally
|
|
158
|
+
```
|
|
187
159
|
|
|
188
|
-
|
|
160
|
+
## MCP Server — Autonomous Agent via Model Context Protocol
|
|
189
161
|
|
|
190
|
-
|
|
191
|
-
import { SubagentConversationTool } from "@thoughtflow/core";
|
|
162
|
+
**Run thoughtflow as an MCP server that any MCP-compatible client can drive.** Claude Desktop, Cursor, OpenCode, Continue, Zed — any client that speaks JSON-RPC over stdio becomes a fully autonomous coding agent with 100+ battle-tested tools.
|
|
192
163
|
|
|
193
|
-
|
|
194
|
-
llmAdapter: adapter,
|
|
195
|
-
model: "gpt-4o",
|
|
196
|
-
tools: [new SubagentConversationTool()],
|
|
197
|
-
});
|
|
164
|
+
### Why thoughtflow MCP?
|
|
198
165
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
)
|
|
166
|
+
| Problem | thoughtflow solution |
|
|
167
|
+
|---|---|
|
|
168
|
+
| **Context window pollution** — 100+ tools with full JSON schemas consume 50K+ tokens upfront | **Smart compressed mode** — tools list shows names + one-liners only. LLM calls `tool_search("analyze codebase")` to pull full schemas on demand. Default: saves ~80% tokens. |
|
|
169
|
+
| **Static tool list** — LLM can't discover the right tool among dozens of similar names | **tool_search** — describe what you want to do in natural language. Returns matching tools with full parameter schemas. Domain-aware: `"testing tools"`, `"workspace tools"`. |
|
|
170
|
+
| **One model for everything** — vision doesn't work on your text model | **Per-provider routing** — route `visionBrowser` to GPT-4V, planning tools to Claude, code tools to your local Qwen. Mix and match. |
|
|
171
|
+
| **Setup complexity** — config files, env vars, provider wiring | **Single config file** — `thoughtflow.config.json`. Providers, tool filtering, model routing, workspace paths — all in one place. |
|
|
172
|
+
|
|
173
|
+
### Quickstart — one command
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
npx @thoughtflow/mcp-server
|
|
202
177
|
```
|
|
203
178
|
|
|
204
|
-
|
|
179
|
+
That's it. The server auto-detects `thoughtflow.config.json` in the current directory. No config file? Starts with sensible defaults (Ollama on localhost).
|
|
180
|
+
|
|
181
|
+
**Custom config:**
|
|
182
|
+
```bash
|
|
183
|
+
npx @thoughtflow/mcp-server --config ./my-config.json
|
|
184
|
+
# or
|
|
185
|
+
THOUGHTFLOW_CONFIG=/path/to/config.json npx @thoughtflow/mcp-server
|
|
186
|
+
```
|
|
205
187
|
|
|
206
|
-
|
|
188
|
+
**Minimal `thoughtflow.config.json`:**
|
|
189
|
+
```json
|
|
190
|
+
{
|
|
191
|
+
"workspace": { "allowedPaths": ["."] },
|
|
192
|
+
"providers": {
|
|
193
|
+
"default": {
|
|
194
|
+
"type": "ollama",
|
|
195
|
+
"baseUrl": "http://localhost:11434",
|
|
196
|
+
"model": "qwen3"
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
207
201
|
|
|
208
|
-
|
|
209
|
-
|
|
202
|
+
Wire into your MCP client:
|
|
203
|
+
|
|
204
|
+
**Claude Desktop** (`claude_desktop_config.json`):
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"mcpServers": {
|
|
208
|
+
"thoughtflow": {
|
|
209
|
+
"command": "npx",
|
|
210
|
+
"args": ["-y", "@thoughtflow/mcp-server", "--config", "/Users/you/project/thoughtflow.config.json"]
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
210
215
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
216
|
+
**Cursor** (`.cursor/mcp.json`):
|
|
217
|
+
```json
|
|
218
|
+
{
|
|
219
|
+
"mcpServers": {
|
|
220
|
+
"thoughtflow": {
|
|
221
|
+
"command": "npx",
|
|
222
|
+
"args": ["-y", "@thoughtflow/mcp-server", "--config", "/absolute/path/to/thoughtflow.config.json"]
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
214
226
|
```
|
|
215
227
|
|
|
216
|
-
|
|
228
|
+
**Zed** (`settings.json`):
|
|
229
|
+
```json
|
|
230
|
+
{
|
|
231
|
+
"context_servers": {
|
|
232
|
+
"thoughtflow": {
|
|
233
|
+
"command": {
|
|
234
|
+
"path": "npx",
|
|
235
|
+
"args": ["-y", "@thoughtflow/mcp-server", "--config", "/absolute/path/to/thoughtflow.config.json"]
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
217
241
|
|
|
218
|
-
|
|
242
|
+
Your LLM now has filesystem access, git, search, code analysis, refactoring, testing — 100+ tools, zero setup beyond the config file. No API keys, no path wrangling, no dependency hell.
|
|
243
|
+
|
|
244
|
+
### The tool_search advantage
|
|
245
|
+
|
|
246
|
+
In compressed mode (default), the LLM receives this instead of 50K tokens of JSON schemas:
|
|
219
247
|
|
|
220
|
-
```ts
|
|
221
|
-
const agent = new Conversation({
|
|
222
|
-
llmAdapter: adapter,
|
|
223
|
-
model: "gpt-4o",
|
|
224
|
-
contextWindow: {
|
|
225
|
-
maxTokens: 8000,
|
|
226
|
-
strategy: "sliding-window", // or "truncation"
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
248
|
```
|
|
249
|
+
## Tool Discovery — USE THIS FIRST
|
|
230
250
|
|
|
231
|
-
|
|
251
|
+
The tool list is COMPRESSED. Use `tool_search` before calling unfamiliar tools.
|
|
232
252
|
|
|
233
|
-
|
|
253
|
+
Available domains:
|
|
254
|
+
- workspace: File I/O, terminal, git, search, browser, HTTP
|
|
255
|
+
- codebase: Repository intelligence — index, search, graphs, impact
|
|
256
|
+
- neural: LLM-powered analysis — review, explain, debug, security
|
|
257
|
+
- planning: Problem decomposition, project management, estimation
|
|
258
|
+
...
|
|
259
|
+
```
|
|
234
260
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
261
|
+
When the LLM needs to read a file:
|
|
262
|
+
```
|
|
263
|
+
LLM: tool_search("read a text file")
|
|
264
|
+
→ readFile: path (string, required), offset (number, optional)...
|
|
265
|
+
LLM: readFile({ path: "src/app.ts" })
|
|
266
|
+
```
|
|
238
267
|
|
|
239
|
-
|
|
268
|
+
Every interaction costs fewer tokens. The LLM discovers tools exactly when needed — like lazy-loading for function schemas.
|
|
269
|
+
|
|
270
|
+
### Vision browser — visual page analysis
|
|
271
|
+
|
|
272
|
+
```json
|
|
273
|
+
{
|
|
274
|
+
"tools": {
|
|
275
|
+
"visionBrowser": {
|
|
276
|
+
"enabled": true,
|
|
277
|
+
"provider": "custom",
|
|
278
|
+
"baseUrl": "https://integrate.api.nvidia.com/v1",
|
|
279
|
+
"apiKey": "***",
|
|
280
|
+
"model": "nemotron-mini-3-omni"
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
```
|
|
240
285
|
|
|
241
|
-
|
|
242
|
-
|
|
286
|
+
Now the LLM can visually inspect rendered web pages:
|
|
287
|
+
```
|
|
288
|
+
LLM: visionBrowser({ url: "https://example.com", prompt: "Is the login form centered? What color is the submit button?" })
|
|
243
289
|
```
|
|
244
290
|
|
|
245
|
-
|
|
291
|
+
Works with any OpenAI-compatible vision endpoint — GPT-4V, Claude 3, Gemini, Nemotron, local Ollama with vision models.
|
|
246
292
|
|
|
247
|
-
|
|
248
|
-
const result = await agent.sendPrompt("Deploy to production", {
|
|
249
|
-
interruptConfig: {
|
|
250
|
-
riskLevel: "high", // auto-interrupt on risky actions
|
|
251
|
-
keywords: ["deploy", "delete", "rm -rf"],
|
|
252
|
-
},
|
|
253
|
-
});
|
|
293
|
+
### Advanced configuration
|
|
254
294
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
295
|
+
```json
|
|
296
|
+
{
|
|
297
|
+
"agent": {
|
|
298
|
+
"toolListMode": "compressed",
|
|
299
|
+
"maxIterations": 50
|
|
300
|
+
},
|
|
301
|
+
"categories": {
|
|
302
|
+
"workspace": { "enabled": true },
|
|
303
|
+
"database": { "enabled": false }
|
|
304
|
+
},
|
|
305
|
+
"tools": {
|
|
306
|
+
"visionBrowser": { "enabled": true, "provider": "custom", "model": "gpt-4o" },
|
|
307
|
+
"browser": { "enabled": false }
|
|
308
|
+
},
|
|
309
|
+
"modelRouting": {
|
|
310
|
+
"vision": { "provider": "openai", "model": "gpt-4o" },
|
|
311
|
+
"planning": { "provider": "claude", "model": "claude-sonnet-4" },
|
|
312
|
+
"default": { "provider": "ollama", "model": "qwen3" }
|
|
313
|
+
},
|
|
314
|
+
"providers": {
|
|
315
|
+
"ollama": { "type": "ollama", "baseUrl": "http://localhost:11434", "model": "qwen3" },
|
|
316
|
+
"openai": { "type": "openai", "baseUrl": "https://api.openai.com/v1", "apiKey": "***" },
|
|
317
|
+
"claude": { "type": "anthropic", "baseUrl": "https://api.anthropic.com", "apiKey": "***" }
|
|
318
|
+
}
|
|
258
319
|
}
|
|
259
320
|
```
|
|
260
321
|
|
|
261
|
-
|
|
322
|
+
| Config key | What it does |
|
|
323
|
+
|---|---|
|
|
324
|
+
| `agent.toolListMode` | `"compressed"` (default, saves tokens) or `"full"` (all schemas upfront) |
|
|
325
|
+
| `categories.*.enabled` | Toggle entire tool categories on/off |
|
|
326
|
+
| `tools.*.enabled` | Toggle individual tools |
|
|
327
|
+
| `modelRouting` | Route specific tools/categories to different LLM providers |
|
|
328
|
+
| `tools.visionBrowser` | Enable visual page analysis with any vision-capable model |
|
|
329
|
+
| `workspace.allowedPaths` | Filesystem sandbox — which directories the LLM can touch |
|
|
262
330
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
Full working examples in [`demos/`](./demos/):
|
|
266
|
-
|
|
267
|
-
| Example | Pattern | What it demonstrates |
|
|
268
|
-
|---------|---------|---------------------|
|
|
269
|
-
| `agent-live-demo.ts` | Single loop + pipeline | Basic agent, multi-agent pipeline (architect → coder → reviewer) |
|
|
270
|
-
| `subagent-demo.ts` | Fan-out | Parent delegates verification tasks, re-verifies output |
|
|
271
|
-
| `code-review-saga-demo.ts` | Saga | 4-step analyze → fix → test → commit with compensating rollback |
|
|
272
|
-
| `code-review-role-orchestrator-demo.ts` | Role orchestrator | 6-role pipeline with journal and artifact passing |
|
|
273
|
-
| `solve-complex-demo.ts` | Dynamic decomposition | Task → 12+ subproblems with dependency tree |
|
|
274
|
-
| `autonomous-dev-demo.ts` | Auto loop | End-to-end: plan → code → build → test → fix in a loop |
|
|
275
|
-
| `autonomous-corporation-demo.ts` | Multi-agent swarm | Multiple agents with different roles collaborating |
|
|
276
|
-
| `multi-server-demo.ts` | Distributed | Pooled inference across multiple LLM servers |
|
|
277
|
-
| `thinking-leak-detection.ts` | Quality gate | Detects reasoning content leaking into agent output |
|
|
278
|
-
| `code-review-autonomous-demo.ts` | Auto review | Automated PR review with skill injection |
|
|
279
|
-
| `tool-calling-test.ts` | Tool loop | Walkthrough of the tool-calling loop mechanics |
|
|
280
|
-
| `workspace-demo.ts` | Workspace | File, git, terminal automation |
|
|
281
|
-
| `nestjs-hello-world-demo.ts` | Skills | Skill-based NestJS code generation |
|
|
282
|
-
| `nestjs-todo-demo.ts` | Skills | Skill-based NestJS TODO app generation |
|
|
331
|
+
### Protocol
|
|
283
332
|
|
|
284
|
-
|
|
333
|
+
Standard MCP over stdio — JSON-RPC 2.0, newline-delimited:
|
|
285
334
|
|
|
286
|
-
|
|
335
|
+
```
|
|
336
|
+
→ {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05"}}
|
|
337
|
+
← {"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2024-11-05","capabilities":{"tools":{}},...}}
|
|
287
338
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
- **Composable.** Conversation, adapters, tools, skills — each piece works independently or together. Use just the event bus, or the full agent stack.
|
|
291
|
-
- **LLM-agnostic.** Switch between OpenAI, Anthropic, Ollama, or vLLM by changing one line.
|
|
292
|
-
- **Pragmatic tooling.** 120+ built-in tools for real workflows — code analysis, refactoring, planning, testing, devops.
|
|
293
|
-
- **Determinism where possible.** Temperature 0, stall detection, max iterations — the framework helps you keep agents predictable.
|
|
339
|
+
→ {"jsonrpc":"2.0","id":2,"method":"tools/list"}
|
|
340
|
+
← {"jsonrpc":"2.0","id":2,"result":{"tools":[{"name":"tool_search",...},{"name":"readFile",...},...]}}
|
|
294
341
|
|
|
295
|
-
|
|
342
|
+
→ {"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"readFile","arguments":{"path":"src/app.ts"}}}
|
|
343
|
+
← {"jsonrpc":"2.0","id":3,"result":{"content":[{"type":"text","text":"..."}]}}
|
|
344
|
+
```
|
|
296
345
|
|
|
297
|
-
|
|
346
|
+
### Testing
|
|
347
|
+
|
|
348
|
+
thoughtflow includes a `MockAdapter` — zero network calls, deterministic responses:
|
|
349
|
+
|
|
350
|
+
```ts
|
|
351
|
+
import { McpServer, MockAdapter } from "thoughtflow";
|
|
352
|
+
|
|
353
|
+
const server = new McpServer({
|
|
354
|
+
thoughtflowConfig: { workspace: { allowedPaths: ["."] } },
|
|
355
|
+
adapters: new Map([["mock", { adapter: new MockAdapter(), model: "mock", baseUrl: "" }]]),
|
|
356
|
+
defaultProvider: "mock",
|
|
357
|
+
});
|
|
358
|
+
await server.initialize();
|
|
359
|
+
|
|
360
|
+
const response = await server.handleRequest({
|
|
361
|
+
jsonrpc: "2.0", id: 1, method: "tools/list",
|
|
362
|
+
});
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Hermes Agent skill
|
|
298
366
|
|
|
367
|
+
Install the thoughtflow skill for Hermes — one command:
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
npx @thoughtflow/mcp-server install-skill
|
|
299
371
|
```
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
├── plugins/ # Workspace, Docker, Browser, Codebase Intelligence
|
|
306
|
-
├── skills/ # Skill loader + built-in .md skill definitions
|
|
307
|
-
├── storage/ # Persistence adapters (memory, JSON, vector stores)
|
|
308
|
-
├── tools/ # 120+ tools across 12 categories
|
|
309
|
-
│ ├── workspace/ # file, git, browser, docker, terminal, ...
|
|
310
|
-
│ ├── codebase/ # search, graph, impact, knowledge, ...
|
|
311
|
-
│ ├── planning/ # breakdown, deps, estimate, risks, ...
|
|
312
|
-
│ ├── quality/ # complexity, coupling, coverage, duplication, ...
|
|
313
|
-
│ ├── refactor/ # rename, extract, split, move, eslint-fix
|
|
314
|
-
│ ├── testing/ # gen-unit, gen-integration, fuzz, snapshot, fix
|
|
315
|
-
│ ├── docs/ # gen-readme, gen-api, gen-adr, check-links
|
|
316
|
-
│ ├── neural/ # review, debug, explain, optimize, security, ...
|
|
317
|
-
│ ├── memory/ # save, recall, context, patterns, lessons
|
|
318
|
-
│ ├── database/ # migration, diagram, index-suggest
|
|
319
|
-
│ └── devops/ # ci-diagnose, deploy-check, docker-optimize, ...
|
|
320
|
-
└── quick/ # Preset configs for common setups
|
|
372
|
+
|
|
373
|
+
This copies the skill to `~/.hermes/skills/thoughtflow-mcp/`. Custom target:
|
|
374
|
+
|
|
375
|
+
```bash
|
|
376
|
+
npx @thoughtflow/mcp-server install-skill --target ~/.agents/skills/
|
|
321
377
|
```
|
|
322
378
|
|
|
323
|
-
|
|
379
|
+
The skill auto-activates when `mcp__thoughtflow__*` tools are detected and teaches the LLM:
|
|
380
|
+
- Task-based tool selection ("find X" → grep, "review" → neuralReview, etc.)
|
|
381
|
+
- Mandatory workflows (pre-change impact check, pre-commit quality gate, visual testing flow)
|
|
382
|
+
- Safety rules (no destructive ops without backup + user approval)
|
|
383
|
+
- Planning pattern (solveComplex → TODO list)
|
|
324
384
|
|
|
325
385
|
## License
|
|
326
386
|
|
|
@@ -328,5 +388,4 @@ MIT — see [LICENSE](LICENSE).
|
|
|
328
388
|
|
|
329
389
|
---
|
|
330
390
|
|
|
331
|
-
*Built with TypeScript. Requires Node.js ≥18.*
|
|
332
|
-
*My first published library — crafted with AI assistance.*
|
|
391
|
+
*Built with TypeScript. Requires Node.js ≥18 or Bun ≥1.2.*
|
|
@@ -79,10 +79,10 @@ class OpenAiAdapter {
|
|
|
79
79
|
this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
80
80
|
// Prevent /v1/v1 double prefix when config already includes /v1
|
|
81
81
|
this.apiUrl = this.baseUrl.endsWith("/v1") ? this.baseUrl : `${this.baseUrl}/v1`;
|
|
82
|
-
this.headers = {
|
|
83
|
-
|
|
84
|
-
Authorization
|
|
85
|
-
}
|
|
82
|
+
this.headers = { "Content-Type": "application/json" };
|
|
83
|
+
if (config.apiKey) {
|
|
84
|
+
this.headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
85
|
+
}
|
|
86
86
|
if (config.organization) {
|
|
87
87
|
this.headers["OpenAI-Organization"] = config.organization;
|
|
88
88
|
}
|