@tabbybyte/kimten 0.1.5 → 0.2.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 +35 -33
- package/index.d.ts +3 -4
- package/lib/kimten.js +5 -6
- package/lib/tools.js +7 -15
- package/package.json +1 -1
- package/lib/prompt.js +0 -13
package/README.md
CHANGED
|
@@ -14,8 +14,8 @@ It’s meant to feel like a smart helper, not a framework.
|
|
|
14
14
|
|
|
15
15
|
## ✅ What it does
|
|
16
16
|
|
|
17
|
-
- Runs a simple agent loop (bounded by `hops`)
|
|
18
|
-
- Lets the model call your
|
|
17
|
+
- Runs a simple, single-agent loop (bounded by `hops`)
|
|
18
|
+
- Lets the LLM model (the brain) call your tool functions (the toys)
|
|
19
19
|
- Keeps short-term conversation memory (in-process, per instance)
|
|
20
20
|
- Supports optional structured output via Zod
|
|
21
21
|
|
|
@@ -24,19 +24,19 @@ It’s meant to feel like a smart helper, not a framework.
|
|
|
24
24
|
- No planners/graphs/state machines
|
|
25
25
|
- No streaming API surface
|
|
26
26
|
- No persistence or long-term memory
|
|
27
|
-
- No plugin system or orchestration
|
|
27
|
+
- No plugin system or multi-agent orchestration
|
|
28
28
|
|
|
29
29
|
---
|
|
30
30
|
|
|
31
31
|
## ✨ Why Kimten?
|
|
32
32
|
|
|
33
|
-
Use it when you just want an agent loop with
|
|
33
|
+
Use it when you just want an agent loop with toys and a little memory, without adopting a larger framework.
|
|
34
34
|
|
|
35
35
|
Good fits:
|
|
36
36
|
|
|
37
37
|
- CLI helpers
|
|
38
38
|
- small automations
|
|
39
|
-
- local
|
|
39
|
+
- local toys
|
|
40
40
|
- scripting
|
|
41
41
|
- quick AI utilities
|
|
42
42
|
- “just let the model call a function” use cases
|
|
@@ -68,9 +68,19 @@ const cat = Kimten({
|
|
|
68
68
|
brain: openai('gpt-4o-mini'), // or, any other available model
|
|
69
69
|
|
|
70
70
|
toys: {
|
|
71
|
-
|
|
71
|
+
randomNumber: {
|
|
72
|
+
description: 'Generate a random integer between min and max (inclusive).',
|
|
73
|
+
inputSchema: z.object({ min: z.number().int(), max: z.number().int() }),
|
|
74
|
+
async execute({ min, max }) {
|
|
75
|
+
const low = Math.min(min, max);
|
|
76
|
+
const high = Math.max(min, max);
|
|
77
|
+
return Math.floor(Math.random() * (high - low + 1)) + low;
|
|
78
|
+
},
|
|
79
|
+
},
|
|
72
80
|
},
|
|
73
81
|
|
|
82
|
+
personality: 'You are a helpful assistant.',
|
|
83
|
+
|
|
74
84
|
hops: 10,
|
|
75
85
|
});
|
|
76
86
|
|
|
@@ -119,19 +129,18 @@ Create a new instance.
|
|
|
119
129
|
|
|
120
130
|
#### Optional
|
|
121
131
|
|
|
122
|
-
* `toys` → object map of tool definitions. Each entry
|
|
123
|
-
* async function shorthand: `async (args) => result`
|
|
132
|
+
* `toys` → object map of toy (tool) definitions. Each entry is:
|
|
124
133
|
* object form: `{ inputSchema?, description?, strict?, execute }`
|
|
125
134
|
default: `{}`
|
|
126
|
-
* `personality` → system
|
|
127
|
-
* `hops` → max agent loop steps (default: `10`)
|
|
128
|
-
prevents infinite zoomies 🌀
|
|
135
|
+
* `personality` → system instructions / prompt for overall behavior description (default: `'You are a helpful assistant.'`)
|
|
136
|
+
* `hops` → max agent loop steps (default: `10`) - prevents infinite zoomies 🌀
|
|
129
137
|
|
|
130
|
-
####
|
|
138
|
+
#### Toy semantics
|
|
131
139
|
|
|
132
|
-
-
|
|
133
|
-
-
|
|
134
|
-
- If a
|
|
140
|
+
- Toy inputs are validated only if you provide `inputSchema`.
|
|
141
|
+
- Toy results should be JSON-serializable; `undefined` becomes `null`.
|
|
142
|
+
- If a toy function throws, Kimten returns `{ error, toolName }` as the toy result (it does not re-throw).
|
|
143
|
+
- Under the hood, each toy is implemented as an AI SDK tool.
|
|
135
144
|
|
|
136
145
|
#### Returns
|
|
137
146
|
|
|
@@ -153,32 +162,25 @@ Create a new instance.
|
|
|
153
162
|
|
|
154
163
|
For the `brain` part, feel free to use any compatible provider and their models.
|
|
155
164
|
|
|
156
|
-
|
|
165
|
+
❗ Note that not all providers (and models) may work out the box with Kimten, particularly for structured output.
|
|
157
166
|
|
|
158
|
-
|
|
167
|
+
💡 Refer to the AI SDK docs: **[providers and models](https://ai-sdk.dev/docs/foundations/providers-and-models)**.
|
|
159
168
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
```js
|
|
163
|
-
toys: {
|
|
164
|
-
readFile,
|
|
165
|
-
writeFile,
|
|
166
|
-
fetchJson,
|
|
167
|
-
runCommand,
|
|
168
|
-
}
|
|
169
|
-
```
|
|
169
|
+
### Add toys freely
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
Define `toys` in object form for strong arg validation and proper selection by the LLM:
|
|
172
172
|
|
|
173
173
|
```js
|
|
174
174
|
import { z } from 'zod';
|
|
175
175
|
|
|
176
176
|
toys: {
|
|
177
|
-
|
|
178
|
-
description: '
|
|
179
|
-
inputSchema: z.object({
|
|
180
|
-
async execute({
|
|
181
|
-
|
|
177
|
+
randomNumber: {
|
|
178
|
+
description: 'Generate a random integer between min and max (inclusive).',
|
|
179
|
+
inputSchema: z.object({ min: z.number().int(), max: z.number().int() }),
|
|
180
|
+
async execute({ min, max }) {
|
|
181
|
+
const low = Math.min(min, max);
|
|
182
|
+
const high = Math.max(min, max);
|
|
183
|
+
return Math.floor(Math.random() * (high - low + 1)) + low;
|
|
182
184
|
},
|
|
183
185
|
},
|
|
184
186
|
}
|
package/index.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ import type { ZodTypeAny, infer as ZodInfer } from 'zod';
|
|
|
2
2
|
|
|
3
3
|
export type BrainModel = Record<string, unknown>;
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type ToolExecute = (args: any) => any | Promise<any>;
|
|
6
6
|
|
|
7
7
|
export type ToyDefinition = {
|
|
8
8
|
inputSchema?: ZodTypeAny;
|
|
9
9
|
description?: string;
|
|
10
10
|
strict?: boolean;
|
|
11
|
-
execute:
|
|
11
|
+
execute: ToolExecute;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export type Toys = Record<string,
|
|
14
|
+
export type Toys = Record<string, ToyDefinition>;
|
|
15
15
|
|
|
16
16
|
export type KimtenConfig = {
|
|
17
17
|
brain: BrainModel;
|
|
@@ -30,4 +30,3 @@ export declare function Kimten(config: KimtenConfig): KimtenAgent;
|
|
|
30
30
|
|
|
31
31
|
declare const _default: typeof Kimten;
|
|
32
32
|
export default _default;
|
|
33
|
-
|
package/lib/kimten.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ToolLoopAgent, stepCountIs, Output } from 'ai';
|
|
2
2
|
import { createMemory } from './memory.js';
|
|
3
|
-
import { buildMessages } from './prompt.js';
|
|
4
3
|
import { normalizeToys } from './tools.js';
|
|
5
4
|
|
|
6
5
|
const DEFAULT_PERSONALITY = 'You are a helpful assistant.';
|
|
@@ -23,9 +22,9 @@ const DEFAULT_PERSONALITY = 'You are a helpful assistant.';
|
|
|
23
22
|
*/
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
25
|
+
* Tool execute function.
|
|
27
26
|
*
|
|
28
|
-
* @callback
|
|
27
|
+
* @callback ToolExecute
|
|
29
28
|
* @param {any} args
|
|
30
29
|
* @returns {any | Promise<any>}
|
|
31
30
|
*/
|
|
@@ -37,13 +36,13 @@ const DEFAULT_PERSONALITY = 'You are a helpful assistant.';
|
|
|
37
36
|
* @property {import('zod').ZodTypeAny} [inputSchema]
|
|
38
37
|
* @property {string} [description]
|
|
39
38
|
* @property {boolean} [strict]
|
|
40
|
-
* @property {
|
|
39
|
+
* @property {ToolExecute} execute
|
|
41
40
|
*/
|
|
42
41
|
|
|
43
42
|
/**
|
|
44
43
|
* Tool registry map.
|
|
45
44
|
*
|
|
46
|
-
* @typedef {Record<string,
|
|
45
|
+
* @typedef {Record<string, ToyDefinition>} Toys
|
|
47
46
|
*/
|
|
48
47
|
|
|
49
48
|
/**
|
|
@@ -155,7 +154,7 @@ export function Kimten(config) {
|
|
|
155
154
|
|
|
156
155
|
const agent = schema ? getStructuredAgent(schema) : textAgent;
|
|
157
156
|
const result = await agent.generate({
|
|
158
|
-
messages:
|
|
157
|
+
messages: memory.list(),
|
|
159
158
|
});
|
|
160
159
|
|
|
161
160
|
const assistantContent =
|
package/lib/tools.js
CHANGED
|
@@ -6,9 +6,9 @@ import { z } from 'zod';
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Tool execute function.
|
|
10
10
|
*
|
|
11
|
-
* @callback
|
|
11
|
+
* @callback ToolExecute
|
|
12
12
|
* @param {any} args
|
|
13
13
|
* @returns {any | Promise<any>}
|
|
14
14
|
*/
|
|
@@ -20,13 +20,13 @@ import { z } from 'zod';
|
|
|
20
20
|
* @property {ZodSchema} [inputSchema]
|
|
21
21
|
* @property {string} [description]
|
|
22
22
|
* @property {boolean} [strict]
|
|
23
|
-
* @property {
|
|
23
|
+
* @property {ToolExecute} execute
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Tool registry map.
|
|
28
28
|
*
|
|
29
|
-
* @typedef {Record<string,
|
|
29
|
+
* @typedef {Record<string, ToyDefinition>} Toys
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
function isPlainObject(value) {
|
|
@@ -41,8 +41,7 @@ function isPlainObject(value) {
|
|
|
41
41
|
/**
|
|
42
42
|
* Normalize a toy registry into AI SDK tool objects.
|
|
43
43
|
*
|
|
44
|
-
* -
|
|
45
|
-
* - Object form: `{ inputSchema?, description?, strict?, execute }`
|
|
44
|
+
* - Object form only: `{ inputSchema?, description?, strict?, execute }`
|
|
46
45
|
*
|
|
47
46
|
* Tool execution is wrapped so thrown errors become JSON-safe results:
|
|
48
47
|
* `{ error, toolName }` (Kimten does not re-throw tool errors).
|
|
@@ -56,7 +55,7 @@ export function normalizeToys(toys) {
|
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
if (!isPlainObject(toys)) {
|
|
59
|
-
throw new TypeError('Kimten config "toys" must be an object map of
|
|
58
|
+
throw new TypeError('Kimten config "toys" must be an object map of tool definitions.');
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
const wrapped = {};
|
|
@@ -86,16 +85,9 @@ export function normalizeToys(toys) {
|
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
function normalizeToyDefinition(name, entry) {
|
|
89
|
-
if (typeof entry === 'function') {
|
|
90
|
-
return {
|
|
91
|
-
inputSchema: z.any(),
|
|
92
|
-
execute: entry,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
88
|
if (!isPlainObject(entry)) {
|
|
97
89
|
throw new TypeError(
|
|
98
|
-
`Kimten tool "${name}" must be
|
|
90
|
+
`Kimten tool "${name}" must be an object with execute(args).`
|
|
99
91
|
);
|
|
100
92
|
}
|
|
101
93
|
|
package/package.json
CHANGED
package/lib/prompt.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build AI SDK messages for a generation call.
|
|
3
|
-
*
|
|
4
|
-
* @param {string} personality System prompt / instructions.
|
|
5
|
-
* @param {Array<{ role: string, content: any }>} history Prior conversation messages.
|
|
6
|
-
* @returns {Array<{ role: string, content: any }>}
|
|
7
|
-
*/
|
|
8
|
-
export function buildMessages(personality, history) {
|
|
9
|
-
return [
|
|
10
|
-
{ role: 'system', content: personality },
|
|
11
|
-
...history,
|
|
12
|
-
];
|
|
13
|
-
}
|