@cognipeer/agent-sdk 0.6.4 → 0.6.6
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 +26 -7
- package/dist/index.cjs +866 -171
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +258 -5
- package/dist/index.d.ts +258 -5
- package/dist/index.mjs +862 -172
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,8 @@ Highlights:
|
|
|
37
37
|
- **Unified reasoning surface** – one `reasoning` config controls provider-native reasoning and post-tool plain-text reflections.
|
|
38
38
|
- **Structured output** – provide a Zod schema and the agent injects a finalize tool to capture JSON deterministically.
|
|
39
39
|
- **Multi-agent and handoffs** – wrap agents as tools or transfer control mid-run with `asTool` / `asHandoff`.
|
|
40
|
-
- **
|
|
40
|
+
- **Human-in-the-loop** – `needsApproval` tools pause for review; `humanInTheLoop.askUser` enables a built-in `ask_user_question` tool that pauses with a structured multi-choice prompt and resumes from the user's answer.
|
|
41
|
+
- **Usage + events** – normalize provider usage, surface `tool_call`, `tool_approval`, `user_question`, `plan`, `summarization`, `reflection`, `metadata`, and `handoff` events.
|
|
41
42
|
- **Structured tracing** – optional per-invoke JSON traces with metadata, payload capture, and pluggable sinks (file, HTTP, Cognipeer, custom).
|
|
42
43
|
|
|
43
44
|
## What’s inside
|
|
@@ -267,6 +268,7 @@ console.log(res.content);
|
|
|
267
268
|
- **Planning discipline** – when planning is enabled the system prompt distinguishes full plan writes from incremental plan updates and emits `plan` events as todos change.
|
|
268
269
|
- **Structured output** – supply `outputSchema` and the framework adds a hidden `response` finalize tool; parsed JSON is returned as `result.output`.
|
|
269
270
|
- **Multi-agent orchestration** – reuse agents via `agent.asTool({ toolName })` or perform handoffs that swap runtimes mid-execution.
|
|
271
|
+
- **Ask the user** – opt in with `humanInTheLoop: { askUser: true }` to give the model an `ask_user_question` tool that pauses the run; resume by calling `agent.resolveUserQuestion(state, { id, answers })`. The global `allowFreeText` flag controls whether "Other" / typed answers are allowed.
|
|
270
272
|
- **MCP + LangChain tools** – any object satisfying the minimal tool interface works; LangChain’s `Tool` implementations plug in directly.
|
|
271
273
|
- **Vision input** – message parts accept base64 or URL images for multimodal requests.
|
|
272
274
|
- **Observability hooks** – `config.onEvent` surfaces tool lifecycle, summarization, reflection, metadata, and final answer events for streaming UIs or CLIs.
|
|
@@ -285,6 +287,7 @@ Examples live under `examples/` with per-folder READMEs. Build the package first
|
|
|
285
287
|
| `summarize-context/` | Summaries + `get_tool_response` raw retrieval. |
|
|
286
288
|
| `structured-output/` | Zod schema finalize tool and parsed outputs. |
|
|
287
289
|
| `rewrite-summary/` | Continue conversations after summaries are injected. |
|
|
290
|
+
| `ask-user/` | Built-in `ask_user_question` tool, structured multi-choice prompt, resume with user's answer. |
|
|
288
291
|
| `multi-agent/` | Delegating between agents via `asTool`. |
|
|
289
292
|
| `handoff/` | Explicit runtime handoffs. |
|
|
290
293
|
| `mcp-tavily/` | MCP remote tool discovery. |
|
|
@@ -333,7 +336,7 @@ Exported helpers (`agent-sdk/src/index.ts`):
|
|
|
333
336
|
**Agent factories:**
|
|
334
337
|
- `createSmartAgent(options)`
|
|
335
338
|
- `createAgent(options)`
|
|
336
|
-
- `createTool({ name, description?, schema, func, needsApproval?, approvalPrompt?, approvalDefaults?, maxExecutionsPerRun? })`
|
|
339
|
+
- `createTool({ name, description?, schema, func, needsApproval?, approvalPrompt?, approvalDefaults?, maxExecutionsPerRun?, cache?, retry? })`
|
|
337
340
|
|
|
338
341
|
**Native providers (no LangChain):**
|
|
339
342
|
- `createProvider(config)` – factory for all six providers
|
|
@@ -348,11 +351,27 @@ Exported helpers (`agent-sdk/src/index.ts`):
|
|
|
348
351
|
|
|
349
352
|
**Utilities:**
|
|
350
353
|
- `buildSystemPrompt(extra?, planning?, name?)`
|
|
351
|
-
-
|
|
352
|
-
|
|
353
|
-
`
|
|
354
|
-
|
|
355
|
-
|
|
354
|
+
- `setTokenCounter`, `getTokenCounter`, `defaultTokenCounter` – swap in a real tokenizer (tiktoken, etc.) globally or per-invoke
|
|
355
|
+
- `resolveToolApprovalState`, `resolveUserQuestionState` – pure helpers behind `agent.resolveToolApproval` / `agent.resolveUserQuestion` for callers that want to apply a resolution outside the agent factory.
|
|
356
|
+
- `createAskUserQuestionTool(stateRef, { allowFreeText, promptOverride })` – exposed for advanced users that want to attach the human-in-the-loop tool manually instead of via `humanInTheLoop.askUser`.
|
|
357
|
+
- Node factories (`nodes/*`), context helpers, token utilities, and full TypeScript types (`SmartAgentOptions`, `SmartState`, `AgentInvokeResult`, `PendingUserQuestion`, `UserQuestionResolution`, etc.).
|
|
358
|
+
|
|
359
|
+
`SmartAgentOptions` accepts the usual suspects (`model`, `tools`, `limits`, `runtimeProfile`, `customProfile`, `useTodoList`, `summarization`, `reasoning`, `usageConverter`, `tracing`, `tokenCounter`, `costEstimator`). See `docs/api/` for detailed type references.
|
|
360
|
+
|
|
361
|
+
**Budget surfaces** (`limits`):
|
|
362
|
+
- `maxToolCalls`, `maxParallelTools`, `maxContextTokens` – classic loop budgets
|
|
363
|
+
- `maxTotalOutputTokens` – cap on cumulative completion tokens
|
|
364
|
+
- `maxCostUsd` – cumulative USD cost (requires `costEstimator`)
|
|
365
|
+
- `maxWallClockMs` – overall wall-clock budget (also available as `InvokeConfig.timeoutMs`)
|
|
366
|
+
|
|
367
|
+
**Tool-level controls** (`createTool`):
|
|
368
|
+
- `maxExecutionsPerRun` – cap successful executions of that tool within a single run
|
|
369
|
+
- `cache` – opt-in per-invoke result cache (`true` or `{ keyFn?, ttlMs? }`)
|
|
370
|
+
- `retry` – per-tool retry policy `{ maxRetries?, backoffMs?, shouldRetry?, circuitBreakerThreshold? }`
|
|
371
|
+
|
|
372
|
+
**Provider-level controls** (`createProvider`):
|
|
373
|
+
- `retry` – automatic 429 / 5xx retry with exponential backoff and `Retry-After` support
|
|
374
|
+
- `prompt_caching: { enabled: true }` – Anthropic `cache_control` and Bedrock `cachePoint` breakpoints for ~90% input-token savings on long tool-heavy runs
|
|
356
375
|
|
|
357
376
|
## Tracing & observability
|
|
358
377
|
|