@cognipeer/agent-sdk 0.4.9 → 0.5.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 +63 -5
- package/dist/index.cjs +2682 -528
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +503 -25
- package/dist/index.d.ts +503 -25
- package/dist/index.mjs +2669 -531
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,15 +53,60 @@ Highlights:
|
|
|
53
53
|
Install the SDK and its (optional) LangChain peer dependency:
|
|
54
54
|
|
|
55
55
|
```sh
|
|
56
|
-
npm install @cognipeer/agent-sdk
|
|
57
|
-
# Optional: LangChain
|
|
58
|
-
npm install @langchain/openai
|
|
56
|
+
npm install @cognipeer/agent-sdk zod
|
|
57
|
+
# Optional: LangChain bindings (if you want to use fromLangchainModel)
|
|
58
|
+
npm install @langchain/core @langchain/openai
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
The SDK includes a built-in native provider layer that talks directly to OpenAI, Anthropic, Azure, Bedrock, Vertex, and any OpenAI-compatible API — no LangChain required.
|
|
62
|
+
|
|
61
63
|
You can also bring your own model adapter as long as it exposes `invoke(messages[])` and (optionally) `bindTools()`.
|
|
62
64
|
|
|
63
65
|
## Quick start
|
|
64
66
|
|
|
67
|
+
### Native provider (no LangChain)
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { createSmartAgent, createTool, createProvider, fromNativeProvider } from "@cognipeer/agent-sdk";
|
|
71
|
+
import { z } from "zod";
|
|
72
|
+
|
|
73
|
+
const echo = createTool({
|
|
74
|
+
name: "echo",
|
|
75
|
+
description: "Echo back user text",
|
|
76
|
+
schema: z.object({ text: z.string() }),
|
|
77
|
+
func: async ({ text }) => ({ echoed: text }),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Pick any provider – OpenAI, Anthropic, Azure, Bedrock, Vertex, or OpenAI-compatible
|
|
81
|
+
const model = fromNativeProvider(
|
|
82
|
+
createProvider({ provider: "openai", apiKey: process.env.OPENAI_API_KEY! }),
|
|
83
|
+
{ model: "gpt-4o" },
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const agent = createSmartAgent({ model, tools: [echo], runtimeProfile: "balanced" });
|
|
87
|
+
const result = await agent.invoke({ messages: [{ role: "user", content: "say hi" }] });
|
|
88
|
+
console.log(result.content);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Switch providers by changing a single config line:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// Anthropic
|
|
95
|
+
createProvider({ provider: "anthropic", apiKey: process.env.ANTHROPIC_API_KEY! })
|
|
96
|
+
|
|
97
|
+
// Azure OpenAI
|
|
98
|
+
createProvider({ provider: "azure", apiKey: "...", endpoint: "https://my-resource.openai.azure.com", deploymentName: "gpt-4o" })
|
|
99
|
+
|
|
100
|
+
// AWS Bedrock
|
|
101
|
+
createProvider({ provider: "bedrock", region: "us-east-1", accessKeyId: "...", secretAccessKey: "..." })
|
|
102
|
+
|
|
103
|
+
// Google Vertex AI
|
|
104
|
+
createProvider({ provider: "vertex", projectId: "my-project", accessToken: process.env.VERTEX_TOKEN })
|
|
105
|
+
|
|
106
|
+
// Any OpenAI-compatible endpoint (Ollama, Groq, Together, vLLM, …)
|
|
107
|
+
createProvider({ provider: "openai-compatible", apiKey: "...", baseURL: "https://custom.endpoint/v1" })
|
|
108
|
+
```
|
|
109
|
+
|
|
65
110
|
### Smart agent (planning + summarization)
|
|
66
111
|
|
|
67
112
|
```ts
|
|
@@ -153,13 +198,14 @@ console.log(res.content);
|
|
|
153
198
|
|
|
154
199
|
## Key capabilities
|
|
155
200
|
|
|
201
|
+
- **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.
|
|
202
|
+
- **Full token tracking** – every response surfaces `inputTokens`, `outputTokens`, `cachedInputTokens`, `cachedWriteTokens`, and `reasoningTokens` for all six providers.
|
|
156
203
|
- **Summarization pipeline** – automatic chunking keeps tool call history within `contextTokenLimit` / `summaryTokenLimit`, archiving originals so `get_tool_response` can fetch them later.
|
|
157
204
|
- **Planning discipline** – when planning is enabled the system prompt distinguishes full plan writes from incremental plan updates and emits `plan` events as todos change.
|
|
158
205
|
- **Structured output** – supply `outputSchema` and the framework adds a hidden `response` finalize tool; parsed JSON is returned as `result.output`.
|
|
159
|
-
- **Usage normalization** – provider `usage` blobs are normalized into `{ prompt_tokens, completion_tokens, total_tokens }` with cached token tracking and totals grouped by model.
|
|
160
206
|
- **Multi-agent orchestration** – reuse agents via `agent.asTool({ toolName })` or perform handoffs that swap runtimes mid-execution.
|
|
161
207
|
- **MCP + LangChain tools** – any object satisfying the minimal tool interface works; LangChain’s `Tool` implementations plug in directly.
|
|
162
|
-
- **Vision input** – message parts accept
|
|
208
|
+
- **Vision input** – message parts accept base64 or URL images for multimodal requests.
|
|
163
209
|
- **Observability hooks** – `config.onEvent` surfaces tool lifecycle, summarization, metadata, and final answer events for streaming UIs or CLIs.
|
|
164
210
|
|
|
165
211
|
## Examples
|
|
@@ -220,11 +266,23 @@ The loop stops when the assistant produces a message without tool calls, a struc
|
|
|
220
266
|
|
|
221
267
|
Exported helpers (`agent-sdk/src/index.ts`):
|
|
222
268
|
|
|
269
|
+
**Agent factories:**
|
|
223
270
|
- `createSmartAgent(options)`
|
|
224
271
|
- `createAgent(options)`
|
|
225
272
|
- `createTool({ name, description?, schema, func, needsApproval?, approvalPrompt?, approvalDefaults?, maxExecutionsPerRun? })`
|
|
273
|
+
|
|
274
|
+
**Native providers (no LangChain):**
|
|
275
|
+
- `createProvider(config)` – factory for all six providers
|
|
276
|
+
- `fromNativeProvider(provider, options?)` – wraps a provider as a `BaseChatModel`
|
|
277
|
+
- `OpenAIProvider`, `AnthropicProvider`, `AzureProvider`, `OpenAICompatibleProvider`, `BedrockProvider`, `VertexProvider`
|
|
278
|
+
- Types: `ChatCompletionRequest`, `ChatCompletionResponse`, `TokenUsage`, `ProviderConfig`
|
|
279
|
+
|
|
280
|
+
**LangChain adapters (optional):**
|
|
226
281
|
- `fromLangchainModel(model)`
|
|
227
282
|
- `withTools(model, tools)`
|
|
283
|
+
- `fromLangchainTools(tools)`
|
|
284
|
+
|
|
285
|
+
**Utilities:**
|
|
228
286
|
- `buildSystemPrompt(extra?, planning?, name?)`
|
|
229
287
|
- Node factories (`nodes/*`), context helpers, token utilities, and full TypeScript types (`SmartAgentOptions`, `SmartState`, `AgentInvokeResult`, etc.).
|
|
230
288
|
|