@cognipeer/agent-sdk 0.3.1 → 0.4.0
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 +36 -9
- package/dist/index.cjs +1930 -290
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +341 -35
- package/dist/index.d.ts +341 -35
- package/dist/index.mjs +1918 -292
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ Lightweight, message-first agent runtime that keeps tool calls transparent, auto
|
|
|
32
32
|
Highlights:
|
|
33
33
|
- **Message-first design** – assistant tool calls and tool responses stay in the transcript.
|
|
34
34
|
- **Token-aware summarization** – chunked rewriting archives oversized tool outputs while exposing `get_tool_response` for lossless retrieval.
|
|
35
|
-
- **Planning mode** –
|
|
35
|
+
- **Planning mode** – adaptive system prompt + TODO tool supports full plan writes and version-safe partial updates.
|
|
36
36
|
- **Structured output** – provide a Zod schema and the agent injects a finalize tool to capture JSON deterministically.
|
|
37
37
|
- **Multi-agent and handoffs** – wrap agents as tools or transfer control mid-run with `asTool` / `asHandoff`.
|
|
38
38
|
- **Usage + events** – normalize provider usage, surface `tool_call`, `plan`, `summarization`, `metadata`, and `handoff` events.
|
|
@@ -73,7 +73,8 @@ const echo = createTool({
|
|
|
73
73
|
name: "echo",
|
|
74
74
|
description: "Echo back user text",
|
|
75
75
|
schema: z.object({ text: z.string().min(1) }),
|
|
76
|
-
func: async ({ text }) => ({ echoed: text })
|
|
76
|
+
func: async ({ text }) => ({ echoed: text }),
|
|
77
|
+
maxExecutionsPerRun: null,
|
|
77
78
|
});
|
|
78
79
|
|
|
79
80
|
const model = fromLangchainModel(new ChatOpenAI({
|
|
@@ -85,8 +86,13 @@ const agent = createSmartAgent({
|
|
|
85
86
|
name: "ResearchHelper",
|
|
86
87
|
model,
|
|
87
88
|
tools: [echo],
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
runtimeProfile: "balanced",
|
|
90
|
+
planning: { mode: "todo", replanPolicy: "on_failure" },
|
|
91
|
+
memory: { provider: "inMemory", scope: "session", writePolicy: "auto_important" },
|
|
92
|
+
summarization: { summaryTriggerTokens: 8000, summaryMode: "incremental" },
|
|
93
|
+
context: { policy: "hybrid", lastTurnsToKeep: 8 },
|
|
94
|
+
toolResponses: { maxToolResponseChars: 4000, maxToolResponseTokens: 1200 },
|
|
95
|
+
limits: { maxToolCalls: 5, maxContextTokens: 12000 },
|
|
90
96
|
tracing: { enabled: true },
|
|
91
97
|
});
|
|
92
98
|
|
|
@@ -98,7 +104,24 @@ const result = await agent.invoke({
|
|
|
98
104
|
console.log(result.content);
|
|
99
105
|
```
|
|
100
106
|
|
|
101
|
-
The smart wrapper
|
|
107
|
+
The smart wrapper now supports runtime presets (`fast`, `balanced`, `deep`, `research`), custom profiles layered on top of a base preset, structured summarization, hybrid context compaction, configurable tool-response retention, in-memory fact storage, delegation limits, and an eval harness via `runSmartAgentEvalHarness(...)`.
|
|
108
|
+
|
|
109
|
+
You can also define a custom profile by extending a built-in preset and overriding only the knobs you need:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
const agent = createSmartAgent({
|
|
113
|
+
name: "CustomPlanner",
|
|
114
|
+
model,
|
|
115
|
+
runtimeProfile: "custom",
|
|
116
|
+
customProfile: {
|
|
117
|
+
extends: "balanced",
|
|
118
|
+
limits: { maxToolCalls: 10, maxContextTokens: 18000 },
|
|
119
|
+
planning: { mode: "todo" },
|
|
120
|
+
context: { lastTurnsToKeep: 10 },
|
|
121
|
+
memory: { writePolicy: "manual" },
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
```
|
|
102
125
|
|
|
103
126
|
### Base agent (minimal loop)
|
|
104
127
|
|
|
@@ -131,7 +154,7 @@ console.log(res.content);
|
|
|
131
154
|
## Key capabilities
|
|
132
155
|
|
|
133
156
|
- **Summarization pipeline** – automatic chunking keeps tool call history within `contextTokenLimit` / `summaryTokenLimit`, archiving originals so `get_tool_response` can fetch them later.
|
|
134
|
-
- **Planning discipline** – when
|
|
157
|
+
- **Planning discipline** – when planning is enabled the system prompt distinguishes full plan writes from incremental plan updates and emits `plan` events as todos change.
|
|
135
158
|
- **Structured output** – supply `outputSchema` and the framework adds a hidden `response` finalize tool; parsed JSON is returned as `result.output`.
|
|
136
159
|
- **Usage normalization** – provider `usage` blobs are normalized into `{ prompt_tokens, completion_tokens, total_tokens }` with cached token tracking and totals grouped by model.
|
|
137
160
|
- **Multi-agent orchestration** – reuse agents via `agent.asTool({ toolName })` or perform handoffs that swap runtimes mid-execution.
|
|
@@ -199,13 +222,15 @@ Exported helpers (`agent-sdk/src/index.ts`):
|
|
|
199
222
|
|
|
200
223
|
- `createSmartAgent(options)`
|
|
201
224
|
- `createAgent(options)`
|
|
202
|
-
- `createTool({ name, description?, schema, func })`
|
|
225
|
+
- `createTool({ name, description?, schema, func, needsApproval?, approvalPrompt?, approvalDefaults?, maxExecutionsPerRun? })`
|
|
203
226
|
- `fromLangchainModel(model)`
|
|
204
227
|
- `withTools(model, tools)`
|
|
205
228
|
- `buildSystemPrompt(extra?, planning?, name?)`
|
|
206
229
|
- Node factories (`nodes/*`), context helpers, token utilities, and full TypeScript types (`SmartAgentOptions`, `SmartState`, `AgentInvokeResult`, etc.).
|
|
207
230
|
|
|
208
|
-
`SmartAgentOptions` accepts the usual suspects (`model`, `tools`, `limits`, `useTodoList`, `summarization`, `usageConverter`, `tracing`). See `docs/api/` for detailed type references.
|
|
231
|
+
`SmartAgentOptions` accepts the usual suspects (`model`, `tools`, `limits`, `runtimeProfile`, `customProfile`, `useTodoList`, `summarization`, `usageConverter`, `tracing`). See `docs/api/` for detailed type references.
|
|
232
|
+
|
|
233
|
+
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`.
|
|
209
234
|
|
|
210
235
|
## Tracing & observability
|
|
211
236
|
|
|
@@ -216,7 +241,9 @@ Enable tracing by passing `tracing: { enabled: true }`. Each invocation writes `
|
|
|
216
241
|
- Optional payload captures (request/response/tool bodies) when `logData` is `true`
|
|
217
242
|
- Aggregated token usage, byte counts, and error summaries for dashboards
|
|
218
243
|
|
|
219
|
-
You can disable payload capture with `logData: false` to keep only metrics, or configure sinks such as `httpSink(url, headers?)`, `cognipeerSink(apiKey, url?)`, or `customSink({ onEvent, onSession })` to forward traces after each run. Sensitive headers/callbacks remain in-memory and are never written alongside the trace.
|
|
244
|
+
You can disable payload capture with `logData: false` to keep only metrics, or configure sinks such as `httpSink(url, headers?)`, `cognipeerSink(apiKey, url?)`, `otlpSink(endpoint, headers?)`, or `customSink({ onEvent, onSession })` to forward traces after each run. Sensitive headers/callbacks remain in-memory and are never written alongside the trace.
|
|
245
|
+
|
|
246
|
+
Each session/event also carries OTel-compatible correlation identifiers (`traceId`, `rootSpanId`, `spanId`, `parentSpanId`) so you can stitch agent traces into distributed telemetry pipelines.
|
|
220
247
|
|
|
221
248
|
## Development
|
|
222
249
|
|