@cognipeer/agent-sdk 0.6.1 → 0.6.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 +58 -8
- package/dist/index.cjs +1 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.mjs +1 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://npmjs.com/package/@cognipeer/agent-sdk) [Docs Website](https://cognipeer.github.io/agent-sdk/)
|
|
4
4
|
|
|
5
|
-
Lightweight, message-first agent runtime that keeps tool calls transparent, automatically summarizes long histories, and ships with planning, multi-agent handoffs, and structured tracing.
|
|
5
|
+
Lightweight, message-first agent runtime that keeps tool calls transparent, supports provider-native reasoning plus post-tool reflection, automatically summarizes long histories, and ships with planning, multi-agent handoffs, and structured tracing.
|
|
6
6
|
|
|
7
7
|
- SDK source: `src/`
|
|
8
8
|
- Examples: `examples/`
|
|
@@ -15,6 +15,7 @@ Lightweight, message-first agent runtime that keeps tool calls transparent, auto
|
|
|
15
15
|
- [Install](#install)
|
|
16
16
|
- [Quick start](#quick-start)
|
|
17
17
|
- [Smart agent (planning + summarization)](#smart-agent-planning--summarization)
|
|
18
|
+
- [Reasoning & reflection](#reasoning--reflection)
|
|
18
19
|
- [Base agent (minimal loop)](#base-agent-minimal-loop)
|
|
19
20
|
- [Key capabilities](#key-capabilities)
|
|
20
21
|
- [Examples](#examples)
|
|
@@ -33,9 +34,10 @@ Highlights:
|
|
|
33
34
|
- **Message-first design** – assistant tool calls and tool responses stay in the transcript.
|
|
34
35
|
- **Token-aware summarization** – chunked rewriting archives oversized tool outputs while exposing `get_tool_response` for lossless retrieval.
|
|
35
36
|
- **Planning mode** – adaptive system prompt + TODO tool supports full plan writes and version-safe partial updates.
|
|
37
|
+
- **Unified reasoning surface** – one `reasoning` config controls provider-native reasoning and post-tool plain-text reflections.
|
|
36
38
|
- **Structured output** – provide a Zod schema and the agent injects a finalize tool to capture JSON deterministically.
|
|
37
39
|
- **Multi-agent and handoffs** – wrap agents as tools or transfer control mid-run with `asTool` / `asHandoff`.
|
|
38
|
-
- **Usage + events** – normalize provider usage, surface `tool_call`, `plan`, `summarization`, `metadata`, and `handoff` events.
|
|
40
|
+
- **Usage + events** – normalize provider usage, surface `tool_call`, `plan`, `summarization`, `reflection`, `metadata`, and `handoff` events.
|
|
39
41
|
- **Structured tracing** – optional per-invoke JSON traces with metadata, payload capture, and pluggable sinks (file, HTTP, Cognipeer, custom).
|
|
40
42
|
|
|
41
43
|
## What’s inside
|
|
@@ -181,6 +183,52 @@ const agent = createSmartAgent({
|
|
|
181
183
|
});
|
|
182
184
|
```
|
|
183
185
|
|
|
186
|
+
### Reasoning & reflection
|
|
187
|
+
|
|
188
|
+
Both `createAgent(...)` and `createSmartAgent(...)` accept a unified `reasoning` config:
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
const agent = createSmartAgent({
|
|
192
|
+
model: fromNativeProvider(
|
|
193
|
+
createProvider({ provider: "openai", apiKey: process.env.OPENAI_API_KEY! }),
|
|
194
|
+
{ model: "gpt-5" },
|
|
195
|
+
),
|
|
196
|
+
tools: [echo],
|
|
197
|
+
reasoning: {
|
|
198
|
+
enabled: true,
|
|
199
|
+
level: "high",
|
|
200
|
+
native: { effort: "high" },
|
|
201
|
+
reflection: {
|
|
202
|
+
cadence: "after_tool",
|
|
203
|
+
mode: "piggyback",
|
|
204
|
+
maxTokens: 450,
|
|
205
|
+
keepLast: 4,
|
|
206
|
+
summarize: false,
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const result = await agent.invoke({
|
|
212
|
+
messages: [{ role: "user", content: "Research the repo and propose the next implementation step." }],
|
|
213
|
+
}, {
|
|
214
|
+
onEvent(event) {
|
|
215
|
+
if (event.type === "reflection") {
|
|
216
|
+
console.log("reflection:", event.text);
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
console.log(result.state?.reflections?.at(-1)?.text);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
What this does:
|
|
225
|
+
|
|
226
|
+
- `reasoning.native` passes provider-specific reasoning knobs through the native provider layer.
|
|
227
|
+
- `reasoning.reflection` adds a short plain-text reflection after qualifying turns without committing that note as a normal assistant message.
|
|
228
|
+
- Reflection notes are persisted on `result.state.reflections`; only the last `keepLast` are re-injected into the next prompt as synthetic system context.
|
|
229
|
+
|
|
230
|
+
Use this only with models/endpoints that actually support provider-native reasoning. Unsupported models usually return a provider error rather than silently degrading.
|
|
231
|
+
|
|
184
232
|
### Base agent (minimal loop)
|
|
185
233
|
|
|
186
234
|
Prefer a tiny core without system prompt or summarization? Use `createAgent`:
|
|
@@ -213,6 +261,7 @@ console.log(res.content);
|
|
|
213
261
|
|
|
214
262
|
- **Native provider layer** – call OpenAI, Anthropic, Azure, Bedrock, Vertex, and any OpenAI-compatible API directly. No LangChain required. Unified `ChatCompletionRequest` / `ChatCompletionResponse` schema with per-provider wire format conversion.
|
|
215
263
|
- **Full token tracking** – every response surfaces `inputTokens`, `outputTokens`, `cachedInputTokens`, `cachedWriteTokens`, and `reasoningTokens` for all six providers.
|
|
264
|
+
- **Unified reasoning controls** – enable provider-native reasoning (`reasoning.native`) and post-tool reflection (`reasoning.reflection`) from one config surface.
|
|
216
265
|
- **Summarization pipeline** – automatic chunking keeps tool call history within `contextTokenLimit` / `summaryTokenLimit`, archiving originals so `get_tool_response` can fetch them later.
|
|
217
266
|
- **Retention controls** – tool outputs can be kept full, reduced to structured previews, archived, or dropped based on size tiers, critical-tool fallback, per-tool overrides, and recent-response pinning.
|
|
218
267
|
- **Planning discipline** – when planning is enabled the system prompt distinguishes full plan writes from incremental plan updates and emits `plan` events as todos change.
|
|
@@ -220,7 +269,7 @@ console.log(res.content);
|
|
|
220
269
|
- **Multi-agent orchestration** – reuse agents via `agent.asTool({ toolName })` or perform handoffs that swap runtimes mid-execution.
|
|
221
270
|
- **MCP + LangChain tools** – any object satisfying the minimal tool interface works; LangChain’s `Tool` implementations plug in directly.
|
|
222
271
|
- **Vision input** – message parts accept base64 or URL images for multimodal requests.
|
|
223
|
-
- **Observability hooks** – `config.onEvent` surfaces tool lifecycle, summarization, metadata, and final answer events for streaming UIs or CLIs.
|
|
272
|
+
- **Observability hooks** – `config.onEvent` surfaces tool lifecycle, summarization, reflection, metadata, and final answer events for streaming UIs or CLIs.
|
|
224
273
|
|
|
225
274
|
## Examples
|
|
226
275
|
|
|
@@ -269,10 +318,11 @@ OPENAI_API_KEY=... npx tsx basic/basic.ts
|
|
|
269
318
|
The agent is a deterministic while-loop – no external graph runtime. Each turn flows through:
|
|
270
319
|
|
|
271
320
|
1. **resolver** – normalize state (messages, counters, limits).
|
|
272
|
-
2. **contextSummarize** (optional) – when token estimates exceed
|
|
321
|
+
2. **contextSummarize** (optional) – when token estimates exceed the active summarization threshold, archive heavy tool outputs.
|
|
273
322
|
3. **agent** – invoke the model (binding tools when supported).
|
|
274
323
|
4. **tools** – execute proposed tool calls with configurable parallelism.
|
|
275
|
-
5. **
|
|
324
|
+
5. **reflect** (optional) – append a plain-text reflection after tool turns when `reasoning.reflection` is enabled.
|
|
325
|
+
6. **toolLimitFinalize** – if tool-call cap is hit, inject a system notice so the next assistant turn must answer directly.
|
|
276
326
|
|
|
277
327
|
The loop stops when the assistant produces a message without tool calls, a structured output finalize signal is observed, or a handoff transfers control. See `docs/architecture/README.md` for diagrams and heuristics.
|
|
278
328
|
|
|
@@ -289,7 +339,7 @@ Exported helpers (`agent-sdk/src/index.ts`):
|
|
|
289
339
|
- `createProvider(config)` – factory for all six providers
|
|
290
340
|
- `fromNativeProvider(provider, options?)` – wraps a provider as a `BaseChatModel`
|
|
291
341
|
- `OpenAIProvider`, `AnthropicProvider`, `AzureProvider`, `OpenAICompatibleProvider`, `BedrockProvider`, `VertexProvider`
|
|
292
|
-
- Types: `ChatCompletionRequest`, `ChatCompletionResponse`, `TokenUsage`, `ProviderConfig`
|
|
342
|
+
- Types: `ChatCompletionRequest`, `ChatCompletionResponse`, `TokenUsage`, `ProviderConfig`, `ReasoningConfig`, `ReflectionRecord`, `ReflectionEvent`
|
|
293
343
|
|
|
294
344
|
**LangChain adapters (optional):**
|
|
295
345
|
- `fromLangchainModel(model)`
|
|
@@ -300,7 +350,7 @@ Exported helpers (`agent-sdk/src/index.ts`):
|
|
|
300
350
|
- `buildSystemPrompt(extra?, planning?, name?)`
|
|
301
351
|
- Node factories (`nodes/*`), context helpers, token utilities, and full TypeScript types (`SmartAgentOptions`, `SmartState`, `AgentInvokeResult`, etc.).
|
|
302
352
|
|
|
303
|
-
`SmartAgentOptions` accepts the usual suspects (`model`, `tools`, `limits`, `runtimeProfile`, `customProfile`, `useTodoList`, `summarization`, `usageConverter`, `tracing`). See `docs/api/` for detailed type references.
|
|
353
|
+
`SmartAgentOptions` accepts the usual suspects (`model`, `tools`, `limits`, `runtimeProfile`, `customProfile`, `useTodoList`, `summarization`, `reasoning`, `usageConverter`, `tracing`). See `docs/api/` for detailed type references.
|
|
304
354
|
|
|
305
355
|
Tools can also declare `maxExecutionsPerRun` to cap successful executions for that tool within a single agent run. Leave it unset or set it to `null` for unlimited usage. This is separate from global limits such as `limits.maxToolCalls` and `limits.maxParallelTools`.
|
|
306
356
|
|
|
@@ -309,7 +359,7 @@ Tools can also declare `maxExecutionsPerRun` to cap successful executions for th
|
|
|
309
359
|
Enable tracing by passing `tracing: { enabled: true }`. Each invocation writes `trace.session.json` into `logs/<SESSION_ID>/` detailing:
|
|
310
360
|
|
|
311
361
|
- Model/provider, agent name/version, limits, and timing metadata
|
|
312
|
-
- Structured events for model calls, tool executions, summaries, and errors
|
|
362
|
+
- Structured events for model calls, tool executions, summaries, reflections, and errors
|
|
313
363
|
- Optional payload captures (request/response/tool bodies) when `logData` is `true`
|
|
314
364
|
- Aggregated token usage, byte counts, and error summaries for dashboards
|
|
315
365
|
|
package/dist/index.cjs
CHANGED
|
@@ -2109,8 +2109,6 @@ var BASE_DEFAULTS = {
|
|
|
2109
2109
|
policy: "hybrid",
|
|
2110
2110
|
lastTurnsToKeep: 8,
|
|
2111
2111
|
toolResponsePolicy: "summarize_archive",
|
|
2112
|
-
archiveLargeToolResponses: true,
|
|
2113
|
-
retrieveArchivedToolResponseOnDemand: true,
|
|
2114
2112
|
budget: {
|
|
2115
2113
|
systemReserveTokens: 1200,
|
|
2116
2114
|
goalsReserveTokens: 1200,
|
|
@@ -2143,8 +2141,7 @@ var BASE_DEFAULTS = {
|
|
|
2143
2141
|
defaultPolicy: "summarize_archive",
|
|
2144
2142
|
toolResponseRetentionByTool: {},
|
|
2145
2143
|
criticalTools: [...DEFAULT_CRITICAL_TOOLS],
|
|
2146
|
-
schemaValidation: "strict"
|
|
2147
|
-
retryOnSchemaError: true
|
|
2144
|
+
schemaValidation: "strict"
|
|
2148
2145
|
}
|
|
2149
2146
|
};
|
|
2150
2147
|
function buildProfile(overrides) {
|