@avee1234/agent-kit 0.1.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/LICENSE +21 -0
- package/README.md +283 -0
- package/dist/index.cjs +657 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +201 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.js +619 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 agent-kit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# agent-kit
|
|
2
|
+
|
|
3
|
+
TypeScript-first library for building stateful, persistent AI agents.
|
|
4
|
+
|
|
5
|
+
## Why agent-kit?
|
|
6
|
+
|
|
7
|
+
- **Persistent memory across sessions** — SQLite store keeps conversation history and auto-summarizes old exchanges. Restart your process; the agent still remembers.
|
|
8
|
+
- **Simple tool system** — define a tool in five lines with `Tool.create`. No decorator magic, no class inheritance.
|
|
9
|
+
- **Built-in observability** — subscribe to `message`, `tool:start`, `tool:end`, and `error` events. No paid add-on required.
|
|
10
|
+
- **TypeScript-first with great types** — strict types throughout. Your editor autocompletes `AgentConfig`, `ToolDefinition`, `AgentEvent`, and everything else.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install agent-kit
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { Agent, Tool, Memory } from 'agent-kit';
|
|
22
|
+
|
|
23
|
+
const echo = Tool.create({
|
|
24
|
+
name: 'echo',
|
|
25
|
+
description: 'Echo a message back',
|
|
26
|
+
parameters: { message: { type: 'string', description: 'Text to echo' } },
|
|
27
|
+
execute: async ({ message }) => String(message),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const agent = new Agent({
|
|
31
|
+
name: 'my-agent',
|
|
32
|
+
memory: new Memory({ store: 'sqlite' }),
|
|
33
|
+
tools: [echo],
|
|
34
|
+
system: 'You are a helpful assistant.',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const response = await agent.chat('Say hello');
|
|
38
|
+
console.log(response.content);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
No model config required — `Agent` ships with a built-in `MockAdapter` so you can develop and test without any API keys.
|
|
42
|
+
|
|
43
|
+
## Research Assistant Demo
|
|
44
|
+
|
|
45
|
+
The `examples/research-assistant` directory contains a full CLI agent that searches the web, saves notes, and remembers research across sessions.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
cd examples/research-assistant
|
|
49
|
+
npm install
|
|
50
|
+
npm start
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Then chat with it:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
> Find recent papers on transformer alternatives
|
|
57
|
+
> What did I research last time?
|
|
58
|
+
> Save a note about Mamba architecture
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Kill the process and restart — memory persists in `research.db`.
|
|
62
|
+
|
|
63
|
+
## Core Concepts
|
|
64
|
+
|
|
65
|
+
### Agent
|
|
66
|
+
|
|
67
|
+
The main class. Runs a tool-calling loop, manages memory context, and emits observability events.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { Agent } from 'agent-kit';
|
|
71
|
+
|
|
72
|
+
const agent = new Agent({
|
|
73
|
+
name: 'assistant',
|
|
74
|
+
model: { provider: 'ollama', model: 'llama3' },
|
|
75
|
+
memory: new Memory({ store: 'sqlite' }),
|
|
76
|
+
tools: [myTool],
|
|
77
|
+
system: 'You are a helpful assistant.',
|
|
78
|
+
maxToolRounds: 10,
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| Option | Type | Default | Description |
|
|
83
|
+
|---|---|---|---|
|
|
84
|
+
| `name` | `string` | required | Unique identifier for this agent |
|
|
85
|
+
| `model` | `ModelAdapter \| ModelConfig` | `MockAdapter` | Model to use for completions |
|
|
86
|
+
| `memory` | `Memory` | none | Memory instance for persistence |
|
|
87
|
+
| `tools` | `Tool[]` | `[]` | Tools the agent can call |
|
|
88
|
+
| `system` | `string` | none | System prompt |
|
|
89
|
+
| `maxToolRounds` | `number` | `10` | Max consecutive tool call rounds |
|
|
90
|
+
|
|
91
|
+
**Methods:**
|
|
92
|
+
|
|
93
|
+
- `agent.chat(input: string): Promise<ModelResponse>` — send a message, get a response
|
|
94
|
+
- `agent.stream(input: string): AsyncIterable<ModelChunk>` — stream the response
|
|
95
|
+
- `agent.on(type, handler)` / `agent.off(type, handler)` — subscribe to events
|
|
96
|
+
|
|
97
|
+
### Tool
|
|
98
|
+
|
|
99
|
+
Wraps a function so the agent can call it.
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { Tool } from 'agent-kit';
|
|
103
|
+
|
|
104
|
+
const getWeather = Tool.create({
|
|
105
|
+
name: 'get_weather',
|
|
106
|
+
description: 'Get current weather for a city',
|
|
107
|
+
parameters: {
|
|
108
|
+
city: { type: 'string', description: 'City name', required: true },
|
|
109
|
+
units: { type: 'string', enum: ['celsius', 'fahrenheit'] },
|
|
110
|
+
},
|
|
111
|
+
execute: async ({ city, units }) => {
|
|
112
|
+
const u = units ?? 'celsius';
|
|
113
|
+
const res = await fetch(`https://wttr.in/${city}?format=j1`);
|
|
114
|
+
return res.json();
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
| Field | Type | Description |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| `name` | `string` | Tool name (used by the model) |
|
|
122
|
+
| `description` | `string` | What the tool does |
|
|
123
|
+
| `parameters` | `Record<string, ParameterDef>` | JSON Schema-style parameter definitions |
|
|
124
|
+
| `execute` | `(params) => Promise<unknown>` | The function to run |
|
|
125
|
+
|
|
126
|
+
`ParameterDef` fields: `type`, `description`, `enum`, `required`.
|
|
127
|
+
|
|
128
|
+
### Memory
|
|
129
|
+
|
|
130
|
+
Manages conversation persistence and context retrieval.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { Memory } from 'agent-kit';
|
|
134
|
+
|
|
135
|
+
// In-memory (default, testing)
|
|
136
|
+
new Memory()
|
|
137
|
+
new Memory({ store: 'memory' })
|
|
138
|
+
|
|
139
|
+
// SQLite (persists across restarts)
|
|
140
|
+
new Memory({ store: 'sqlite' })
|
|
141
|
+
new Memory({ store: 'sqlite', path: './myagent.db' })
|
|
142
|
+
|
|
143
|
+
// Custom store
|
|
144
|
+
new Memory({ store: myCustomStore })
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
| Option | Type | Default | Description |
|
|
148
|
+
|---|---|---|---|
|
|
149
|
+
| `store` | `'memory' \| 'sqlite' \| MemoryStore` | `'memory'` | Storage backend |
|
|
150
|
+
| `path` | `string` | `./agent-memory.db` | SQLite file path (sqlite only) |
|
|
151
|
+
| `windowSize` | `number` | `20` | Number of recent messages to include in context |
|
|
152
|
+
| `summarizeAfter` | `number` | `20` | Summarize after this many new messages |
|
|
153
|
+
|
|
154
|
+
Auto-summarization: when `summarizeAfter` messages accumulate, the agent summarizes them and stores the summary. Older context is retrieved via `searchSummaries`.
|
|
155
|
+
|
|
156
|
+
## Model Configuration
|
|
157
|
+
|
|
158
|
+
### Mock (zero config, built-in)
|
|
159
|
+
|
|
160
|
+
If you omit `model`, the agent uses `MockAdapter` — it echoes inputs and simulates tool calls. Useful for testing.
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { MockAdapter } from 'agent-kit';
|
|
164
|
+
|
|
165
|
+
const agent = new Agent({ name: 'test', model: new MockAdapter() });
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Ollama (local models)
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
const agent = new Agent({
|
|
172
|
+
name: 'local-agent',
|
|
173
|
+
model: { provider: 'ollama', model: 'llama3' },
|
|
174
|
+
// baseURL defaults to http://localhost:11434/v1
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### OpenAI-compatible endpoints
|
|
179
|
+
|
|
180
|
+
Works with Together AI, OpenRouter, Anyscale, LM Studio, and any other OpenAI-compatible API.
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { OpenAICompatibleAdapter } from 'agent-kit';
|
|
184
|
+
|
|
185
|
+
const agent = new Agent({
|
|
186
|
+
name: 'agent',
|
|
187
|
+
model: new OpenAICompatibleAdapter({
|
|
188
|
+
baseURL: 'https://api.together.xyz/v1',
|
|
189
|
+
model: 'meta-llama/Llama-3-70b-chat-hf',
|
|
190
|
+
apiKey: process.env.TOGETHER_API_KEY,
|
|
191
|
+
}),
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Events
|
|
196
|
+
|
|
197
|
+
Subscribe to events for logging, tracing, or custom observability.
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
agent.on('message', (e) => {
|
|
201
|
+
console.log(`[${e.data.role}] ${e.data.content}`);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
agent.on('tool:start', (e) => {
|
|
205
|
+
console.log(`Calling ${e.data.toolName}...`);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
agent.on('tool:end', (e) => {
|
|
209
|
+
console.log(`${e.data.toolName} finished in ${e.latencyMs}ms`);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
agent.on('memory:retrieve', (e) => {
|
|
213
|
+
console.log(`Loaded ${e.data.recentMessages} messages, ${e.data.summaries} summaries`);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
agent.on('error', (e) => {
|
|
217
|
+
console.error(`Error: ${e.data.message}`);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// Catch all events
|
|
221
|
+
agent.on('*', (e) => {
|
|
222
|
+
myTracer.record(e);
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
| Event type | `data` fields | Description |
|
|
227
|
+
|---|---|---|
|
|
228
|
+
| `message` | `role`, `content` | User or assistant message |
|
|
229
|
+
| `tool:start` | `toolName`, `toolCallId`, `arguments` | Tool call started |
|
|
230
|
+
| `tool:end` | `toolName`, `toolCallId`, `result`, `latencyMs` | Tool call finished |
|
|
231
|
+
| `memory:retrieve` | `recentMessages`, `summaries` | Memory context loaded |
|
|
232
|
+
| `error` | `message`, `toolName`, `toolCallId` | Error during tool execution |
|
|
233
|
+
|
|
234
|
+
All events include `type`, `timestamp`, and `agentId` fields from `AgentEvent`.
|
|
235
|
+
|
|
236
|
+
## Custom MemoryStore
|
|
237
|
+
|
|
238
|
+
Implement the `MemoryStore` interface to plug in any storage backend (PostgreSQL, Redis, DynamoDB, etc.).
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import type { MemoryStore } from 'agent-kit';
|
|
242
|
+
import type { Message, Summary } from 'agent-kit';
|
|
243
|
+
|
|
244
|
+
class MyStore implements MemoryStore {
|
|
245
|
+
async saveMessages(agentId: string, messages: Message[]): Promise<void> {
|
|
246
|
+
// persist messages
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async getRecentMessages(agentId: string, limit: number): Promise<Message[]> {
|
|
250
|
+
// return most recent `limit` messages
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async saveSummary(agentId: string, summary: Summary): Promise<void> {
|
|
254
|
+
// persist summary
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async searchSummaries(agentId: string, query: string, limit: number): Promise<Summary[]> {
|
|
258
|
+
// return relevant summaries (keyword or vector search)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const agent = new Agent({
|
|
263
|
+
name: 'agent',
|
|
264
|
+
memory: new Memory({ store: new MyStore() }),
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## What You Can Build
|
|
269
|
+
|
|
270
|
+
- **Research assistant** — web search + note-taking + session memory
|
|
271
|
+
- **Customer support bot** — ticket creation + knowledge base lookup + conversation history
|
|
272
|
+
- **Code reviewer** — file read/write tools + PR comment integration
|
|
273
|
+
- **Data analyst** — SQL query tool + chart generation + persistent findings
|
|
274
|
+
- **Personal assistant** — calendar access + email tools + long-term user preferences
|
|
275
|
+
- **DevOps incident responder** — log search + runbook lookup + alert suppression
|
|
276
|
+
|
|
277
|
+
## Contributing
|
|
278
|
+
|
|
279
|
+
Bug reports and pull requests welcome. Open an issue to discuss changes before submitting a PR.
|
|
280
|
+
|
|
281
|
+
## License
|
|
282
|
+
|
|
283
|
+
MIT
|