orbitx 0.3.5 → 0.3.7

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/docs/agents.md CHANGED
@@ -17,6 +17,7 @@ new BaseAgent({
17
17
  aiProvider: AIProvider | AgentProviderEntry[]; // see Providers doc
18
18
  mcpClient: MCPClient;
19
19
  skills?: Skill[];
20
+ compactInstructions?: string; // what a compact_memory note must also keep in this app (see Memory compaction)
20
21
  maxMemorizeToken?: number; // default: derived from the main provider's contextWindow * safeUsageRatio
21
22
  initData?: {
22
23
  compactMemory: string;
@@ -99,13 +100,17 @@ For a **streaming** call, an abort doesn't throw the turn away: `chat()` resolve
99
100
 
100
101
  ## Memory compaction
101
102
 
102
- OrbitX never truncates or deletes conversation history. Compaction happens through a real, always-available native tool — `compact_memory({ new_memory: string, continue_iterating?: boolean })` — that `BaseAgent` appends to every tool schema list alongside whatever MCP tools you allowed. This means the model can compact its own context whenever *it* judges the conversation has grown long, not only when forced to.
103
+ OrbitX never truncates or deletes conversation history. Compaction happens through a real, always-available native tool — `compact_memory({ new_memory: string, language?: string, files_to_reread?: {path, reason}[], continue_iterating?: boolean })` — that `BaseAgent` appends to every tool schema list alongside whatever MCP tools you allowed. This means the model can compact its own context whenever *it* judges the conversation has grown long, not only when forced to.
103
104
 
104
105
  Calling `compact_memory`:
105
106
 
106
- 1. Replaces the running `compactMemory` string with `new_memory`, which is injected into every future system prompt (`MEMORY:` section). The cached system prompt is invalidated at the same time, so the very next turn's system prompt is rebuilt with the new summary rather than replaying the stale one.
107
+ 1. Replaces the running `compactMemory` string with `new_memory` — followed by a `Conversation language: …` line when `language` is given and a `Files to read again …` list from `files_to_reread` (so both survive a restore from `AgentState` without a new field) — which is injected into every future system prompt (`MEMORY:` section). The cached system prompt is invalidated at the same time, so the very next turn's system prompt is rebuilt with the new summary rather than replaying the stale one.
107
108
  2. Once every tool call in that turn has been dispatched and had its normal tool-response message appended to `messagesCompact` — `compact_memory`'s own response included — the *entire* turn's `messagesCompact` (the assistant message, every tool-response message, all of it) is moved into `retiredMessages` and `messagesCompact` is cleared. Nothing is lost, it's just retired from what gets replayed to the model every turn. Nothing needs to be separately "rolled into a lifetime total" — every message already carries its own `usage`, so `getFullTotalToken()` (see [Token accounting](#token-accounting)) just sums `retiredMessages` + `messagesCompact` directly.
108
- 3. A single hidden `role: "user"` message — `"Memory compacted. Continue where you left off, using MEMORY above for context."` — is pushed onto the now-empty `messagesCompact`, but *only if `run()` is actually about to take another turn right now* (see `continue_iterating` below for when it isn't). With nothing left to respond to it this turn, an unconditional push would just leave it sitting in `messagesCompact` as a stray, unanswered `"user"` entry until some later, unrelated user message showed up after it. When it is added, the model's next turn already has the new summary via the system prompt's MEMORY section, so nothing about the compacted turn — including the `compact_memory` call/response pair itself — needs to stay in the replayed working context; the message is just the nudge to keep going.
109
+ 3. A single hidden `role: "user"` message — `"Memory compacted. Continue where you left off, using MEMORY above for context."`, followed by the user's latest real (non-hidden) message verbatim (clipped to its head and tail past 6 000 characters), the files to read again, and the language to reply in — is pushed onto the now-empty `messagesCompact`, but *only if `run()` is actually about to take another turn right now* (see `continue_iterating` below for when it isn't). With nothing left to respond to it this turn, an unconditional push would just leave it sitting in `messagesCompact` as a stray, unanswered `"user"` entry until some later, unrelated user message showed up after it. When it is added, the model's next turn already has the new summary via the system prompt's MEMORY section, so nothing about the compacted turn — including the `compact_memory` call/response pair itself — needs to stay in the replayed working context; the message is just the nudge to keep going.
110
+
111
+ ### What a note keeps
112
+
113
+ Only the note, the language, the files to read again and the user's latest message cross a compaction; every tool result and file content in the working context is dropped. The tool's own descriptions and a `COMPACTION RULES:` block in the system prompt tell the model to write the note as a hand-over — the user's requests and constraints, what's done, decisions, the exact next steps, open questions — and to name files by path in `files_to_reread` instead of copying their contents (a re-read costs less than carrying them in every later system prompt). Carrying the user's own words over is what keeps the model answering in their language and on their request after a compaction. An application adds its own must-keep items with the `compactInstructions` constructor option (appended to those rules).
109
114
 
110
115
  Archiving is deliberately deferred until the whole turn is dispatched, rather than happening the instant `compact_memory` itself resolves: providers reject a `"tool"`-role message that isn't preceded, in the same request, by the assistant message carrying the `tool_calls` it's answering, so archiving mid-turn would strand the response of any *other* tool call made alongside `compact_memory` in the same turn. Doing it once, after every call in the turn already has its response in `messagesCompact`, avoids that regardless of how many other tools were called or in what order.
111
116
 
@@ -161,9 +166,13 @@ Every other `type` entry comes from a tool calling `mcp.executeProvider(toolCall
161
166
  - `getCompactTotalTokens(type: ProviderType)` / `getFullTotalToken(type: ProviderType)` — return `{ total, inputHit, inputMiss, output }`, summing `unit: "tokens"` entries matching `type` over `messagesCompact` only, or `retiredMessages` + `messagesCompact` (this agent's whole lifetime), respectively.
162
167
  - `getCompactTotalCost(type: ProviderType)` / `getFullTotalCost(type: ProviderType)` — return a plain `number`, summing `unit: "cost"` entries matching `type` over the same two scopes.
163
168
 
169
+ ## Tool schemas
170
+
171
+ Each run sends the model the tools `mcpClient.getTools()` reports, filtered to `allowedTools`, plus `compact_memory`. A remote tool that reports no inputs at all (a bare proxy that only forwards calls, e.g. a desktop app relaying a browser extension's tools) takes the description and inputs of the `allowedTools` entry with the same name, so the model still sees its parameters; a remote tool that publishes its own inputs is sent as published.
172
+
164
173
  ## Instructions, skills, and memory in the system prompt
165
174
 
166
- The system prompt is built lazily on first use and cached — a stable prefix between compactions, which matters for provider-side prompt caching. It's assembled from: a fixed "you have tools" preamble, each skill's name/description/instructions (see [Skills](./skills.md)), the current `MEMORY:` block (sourced from `compactMemory`), and your `instruction` string, in that order. Each `compact_memory` call invalidates the cache (see [Memory compaction](#memory-compaction)), so the next turn's system prompt is rebuilt with the fresh `MEMORY:` block instead of the one that was current when the prompt was first built.
175
+ The system prompt is built lazily on first use and cached — a stable prefix between compactions, which matters for provider-side prompt caching. It's assembled from: a fixed "you have tools" preamble, each skill's name/description/instructions (see [Skills](./skills.md)), the current `MEMORY:` block (sourced from `compactMemory`) followed by the `COMPACTION RULES:` block (plus `compactInstructions`), and your `instruction` string, in that order. Each `compact_memory` call invalidates the cache (see [Memory compaction](#memory-compaction)), so the next turn's system prompt is rebuilt with the fresh `MEMORY:` block instead of the one that was current when the prompt was first built.
167
176
 
168
177
  ## `StatelessAgent`
169
178
 
@@ -1,59 +1,59 @@
1
- # API Reference
2
-
3
- Flat index of every public export from `orbitx` (see `src/index.ts`), grouped by area. Each links to the doc page with the actual explanation and examples.
4
-
5
- ## Core / Providers — see [Providers](./providers.md)
6
-
7
- - `AIProvider` (abstract base class)
8
- - `OpenAIProvider`, `AnthropicProvider`, `DeepSeekProvider`, `OllamaProvider`
9
- - `resolveAgentProviders()`, `ProviderRegistry`
10
- - Types: `AgentProviderEntry`, `AgentProvidersInput`
11
- - Types: `ChatResponse`, `Message`, `MessageUsage`, `MessageUsageTokens`, `MessageUsageCost`, `StreamCallback`, `ToolSchema`, `ToolCallRequest`, `MessageContentPart`, `ProviderCapabilities`, `ProviderType` — see [Providers](./providers.md#provider-roles)
12
- - `resolveThinkEffortLevel()`, `clampThinkEffort()` — the universal 0-1 `thinkEffort` → provider-native-level mapping helpers; see [Providers](./providers.md#think-effort)
13
- - Type: `ThinkEffortLevel`
14
- - `toOpenAIFunctionTools()` — translates a `ToolSchema[]` into OpenAI's function-calling format; exported for building custom providers.
15
-
16
- ## Agents — see [Agents](./agents.md)
17
-
18
- - `BaseAgent`
19
- - `SimpleAgent`
20
- - Types: `ExtractedSegment`, `ParsedToolCall`
21
-
22
- ## Swarm — see [Swarm](./swarm.md)
23
-
24
- - `SwarmBase` — types `SwarmBaseProps`, `SwarmRunOptions`, `SwarmState`, `SwarmAgentState`, `SwarmStreamChunk`, `SwarmStreamCallback`, `SwarmAgentFailure`
25
- - `AgentDefinition`, `selectTools()`, `applyTextOverride()` — types `AgentDefinitionProps`, `AgentOverrides`, `AgentFactory`, `AgentFactoryOptions`, `TextOverride`
26
- - Ready-made definitions: `PlannerAgent`, `ReasonerAgent` (+ `REASONER_PANEL_MS`), `BackendAgent`, `FrontendAgent`, `TestAgent`, `ResearchAgent`, `DefaultAgents()`, and the shared instruction fragments `PLANNER_PROTOCOL` / `WORKER_PROTOCOL` / `TEAM_PROTOCOL` / `PRODUCTION_BAR`
27
-
28
- ## Tools — see [Tools](./tools.md)
29
-
30
- - `MCPTool`, `generateRefId()`, `normalizeToolOutput()`
31
- - Types: `MCP`, `MCPToolOutput`
32
-
33
- Built-in tool factories, grouped by domain (each domain also exports a `*Tools()` array):
34
-
35
- | Domain | Exports |
36
- |---|---|
37
- | Filesystem | `FsReadFileTool`, `FsWriteFileTool`, `FsEditFileTool`, `FsListDirTool`, `FsCreateDirTool`, `FsDeleteTool`, `FsMoveTool`, `FsStatTool`, `FsTools` |
38
- | Bash | `BashRunTool`, `BashWaitTool`, `BashLogsTool`, `BashListTool`, `BashWriteInputTool`, `BashTerminateTool`, `BashTools` |
39
- | Browser | `BrowserCreateSessionTool`, `BrowserRemoveSessionTool`, `BrowserGetSessionsTool`, `BrowserNavigateTool`, `BrowserConsoleTool`, `BrowserInjectTool`, `BrowserReadTool`, `BrowserClickTool`, `BrowserFillTool`, `BrowserScrollInfoTool`, `BrowserScrollTool`, `BrowserNetworkStatusTool`, `BrowserNetworkTool`, `BrowserSubmitFormTool`, `BrowserScreenshotTool`, `BrowserTools` |
40
- | Todo | `TodoCreateListTool`, `TodoRemoveListTool`, `TodoGetListsTool`, `TodoGetListTool`, `TodoCreateTaskTool`, `TodoRemoveTaskTool`, `TodoCheckTaskTool`, `TodoTools`, types `TodoTask`, `TodoList` |
41
- | Present | `PresentAddTool`, `PresentClearTool`, `PresentGetListTool`, `PresentTools`, `getPresentFolder()` |
42
- | Question/Answer | `QuestionAnswerTool`, `QuestionAnswerTools` |
43
- | Utility | `GetCurrentTimeTool`, `DelayTool`, `ReadImageTool`, `UtilTools` |
44
- | Swarm | `getAgentTools(options?)`, `AgentTypesTool`, `AgentHireTool`, `AgentFireTool`, `AgentActiveTool`, `AgentPromptTool`, `AgentReportParentTool`, `AgentReportGroupTool`, `AgentToolsRegistry`, types `AgentToolsOptions`, `AgentToolsHandle`, `SwarmController`, `SwarmAgentTypeInfo`, `SwarmAgentInfo`, `AgentToolsEvent`, `AgentToolsAck`, `AgentToolsListener` — see [Swarm](./swarm.md#getagenttoolsoptions) |
45
-
46
- ## Skills — see [Skills](./skills.md)
47
-
48
- - `Skill`
49
- - `BackendSecuritySkill`, `BigTaskSkill`, `CodeVerificationSkill`, `LongTaskEfficiencySkill`, `NodeBackendSkill`, `PlannerSkill`, `PresentSkill`, `QuestionAnswerSkill`, `ReactFrontendSkill`, `ResearchSkill`, `UiUxDesignSkill`, `WebEndToEndTestSkill`
50
-
51
- ## MCP transport — see [MCP Architecture](./mcp-architecture.md)
52
-
53
- - `MCPServer`, `MCPClient`
54
- - `MCPConnection`, `MCPIPCConnection`, `MCPWSConnection`
55
- - `MCPComputer`, type `MCPComputerOptions` *(experimental)*
56
- - `MCPStorage`, `MCPFSStorage`
57
- - `MCPRNG`
58
- - `MCPOutputFilter` (`MCPFilter` is a deprecated alias, removed in `1.0.0`)
59
- - `MCPExecutionPolicy`, `MCPBypassExecutionPolicy`, type `MCPToolCallRequest`
1
+ # API Reference
2
+
3
+ Flat index of every public export from `orbitx` (see `src/index.ts`), grouped by area. Each links to the doc page with the actual explanation and examples.
4
+
5
+ ## Core / Providers — see [Providers](./providers.md)
6
+
7
+ - `AIProvider` (abstract base class)
8
+ - `OpenAIProvider`, `AnthropicProvider`, `DeepSeekProvider`, `OllamaProvider`
9
+ - `resolveAgentProviders()`, `ProviderRegistry`
10
+ - Types: `AgentProviderEntry`, `AgentProvidersInput`
11
+ - Types: `ChatResponse`, `Message`, `MessageUsage`, `MessageUsageTokens`, `MessageUsageCost`, `StreamCallback`, `ToolSchema`, `ToolCallRequest`, `MessageContentPart`, `ProviderCapabilities`, `ProviderType` — see [Providers](./providers.md#provider-roles)
12
+ - `resolveThinkEffortLevel()`, `clampThinkEffort()` — the universal 0-1 `thinkEffort` → provider-native-level mapping helpers; see [Providers](./providers.md#think-effort)
13
+ - Type: `ThinkEffortLevel`
14
+ - `toOpenAIFunctionTools()` — translates a `ToolSchema[]` into OpenAI's function-calling format; exported for building custom providers.
15
+
16
+ ## Agents — see [Agents](./agents.md)
17
+
18
+ - `BaseAgent`
19
+ - `SimpleAgent`
20
+ - Types: `ExtractedSegment`, `ParsedToolCall`
21
+
22
+ ## Swarm — see [Swarm](./swarm.md)
23
+
24
+ - `SwarmBase` — types `SwarmBaseProps`, `SwarmRunOptions`, `SwarmState`, `SwarmAgentState`, `SwarmStreamChunk`, `SwarmStreamCallback`, `SwarmAgentFailure`
25
+ - `AgentDefinition`, `selectTools()`, `applyTextOverride()` — types `AgentDefinitionProps`, `AgentOverrides`, `AgentFactory`, `AgentFactoryOptions`, `TextOverride`
26
+ - Ready-made definitions: `PlannerAgent`, `ReasonerAgent` (+ `REASONER_PANEL_MS`), `BackendAgent`, `FrontendAgent`, `TestAgent`, `ResearchAgent`, `DefaultAgents()`, and the shared instruction fragments `PLANNER_PROTOCOL` / `WORKER_PROTOCOL` / `TEAM_PROTOCOL` / `PRODUCTION_BAR`
27
+
28
+ ## Tools — see [Tools](./tools.md)
29
+
30
+ - `MCPTool`, `generateRefId()`, `normalizeToolOutput()`
31
+ - Types: `MCP`, `MCPToolOutput`
32
+
33
+ Built-in tool factories, grouped by domain (each domain also exports a `*Tools()` array):
34
+
35
+ | Domain | Exports |
36
+ |---|---|
37
+ | Filesystem | `FsReadFileTool`, `FsWriteFileTool`, `FsEditFileTool`, `FsListDirTool`, `FsCreateDirTool`, `FsDeleteTool`, `FsMoveTool`, `FsStatTool`, `FsTools` |
38
+ | Bash | `BashRunTool`, `BashWaitTool`, `BashLogsTool`, `BashListTool`, `BashWriteInputTool`, `BashTerminateTool`, `BashTools` |
39
+ | Browser | `BrowserCreateSessionTool`, `BrowserRemoveSessionTool`, `BrowserGetSessionsTool`, `BrowserNavigateTool`, `BrowserConsoleTool`, `BrowserInjectTool`, `BrowserReadTool`, `BrowserClickTool`, `BrowserFillTool`, `BrowserScrollInfoTool`, `BrowserScrollTool`, `BrowserNetworkStatusTool`, `BrowserNetworkTool`, `BrowserSubmitFormTool`, `BrowserScreenshotTool`, `BrowserTools` |
40
+ | Todo | `TodoCreateListTool`, `TodoRemoveListTool`, `TodoGetListsTool`, `TodoGetListTool`, `TodoCreateTaskTool`, `TodoRemoveTaskTool`, `TodoCheckTaskTool`, `TodoTools`, types `TodoTask`, `TodoList` |
41
+ | Present | `PresentAddTool`, `PresentClearTool`, `PresentGetListTool`, `PresentTools`, `getPresentFolder()` |
42
+ | Question/Answer | `QuestionAnswerTool`, `QuestionAnswerTools` |
43
+ | Utility | `GetCurrentTimeTool`, `DelayTool`, `ReadImageTool`, `UtilTools` |
44
+ | Swarm | `getAgentTools(options?)`, `AgentTypesTool`, `AgentHireTool`, `AgentFireTool`, `AgentActiveTool`, `AgentPromptTool`, `AgentReportParentTool`, `AgentReportGroupTool`, `AgentToolsRegistry`, types `AgentToolsOptions`, `AgentToolsHandle`, `SwarmController`, `SwarmAgentTypeInfo`, `SwarmAgentInfo`, `AgentToolsEvent`, `AgentToolsAck`, `AgentToolsListener` — see [Swarm](./swarm.md#getagenttoolsoptions) |
45
+
46
+ ## Skills — see [Skills](./skills.md)
47
+
48
+ - `Skill`
49
+ - `BackendSecuritySkill`, `BigTaskSkill`, `CodeVerificationSkill`, `LongTaskEfficiencySkill`, `NodeBackendSkill`, `PlannerSkill`, `PresentSkill`, `QuestionAnswerSkill`, `ReactFrontendSkill`, `ResearchSkill`, `UiUxDesignSkill`, `WebEndToEndTestSkill`
50
+
51
+ ## MCP transport — see [MCP Architecture](./mcp-architecture.md)
52
+
53
+ - `MCPServer`, `MCPClient`
54
+ - `MCPConnection`, `MCPIPCConnection`, `MCPWSConnection`
55
+ - `MCPComputer`, type `MCPComputerOptions` *(experimental)*
56
+ - `MCPStorage`, `MCPFSStorage`
57
+ - `MCPRNG`
58
+ - `MCPOutputFilter` (`MCPFilter` is a deprecated alias, removed in `1.0.0`)
59
+ - `MCPExecutionPolicy`, `MCPBypassExecutionPolicy`, type `MCPToolCallRequest`