@agentuity/cli 0.0.101 → 0.0.102
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/AGENTS.md +19 -188
- package/bin/cli.ts +13 -6
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +41 -12
- package/dist/cli.js.map +1 -1
- package/dist/cmd/ai/index.d.ts.map +1 -1
- package/dist/cmd/ai/index.js +6 -1
- package/dist/cmd/ai/index.js.map +1 -1
- package/dist/cmd/ai/prompt/agent.d.ts +7 -0
- package/dist/cmd/ai/prompt/agent.d.ts.map +1 -1
- package/dist/cmd/ai/prompt/agent.js +12 -323
- package/dist/cmd/ai/prompt/agent.js.map +1 -1
- package/dist/cmd/ai/prompt/api.d.ts +7 -0
- package/dist/cmd/ai/prompt/api.d.ts.map +1 -1
- package/dist/cmd/ai/prompt/api.js +12 -260
- package/dist/cmd/ai/prompt/api.js.map +1 -1
- package/dist/cmd/ai/prompt/version.d.ts +35 -0
- package/dist/cmd/ai/prompt/version.d.ts.map +1 -0
- package/dist/cmd/ai/prompt/version.js +55 -0
- package/dist/cmd/ai/prompt/version.js.map +1 -0
- package/dist/cmd/ai/prompt/web.d.ts +7 -0
- package/dist/cmd/ai/prompt/web.d.ts.map +1 -1
- package/dist/cmd/ai/prompt/web.js +12 -283
- package/dist/cmd/ai/prompt/web.js.map +1 -1
- package/dist/cmd/ai/skills/generate.d.ts +3 -0
- package/dist/cmd/ai/skills/generate.d.ts.map +1 -0
- package/dist/cmd/ai/skills/generate.js +65 -0
- package/dist/cmd/ai/skills/generate.js.map +1 -0
- package/dist/cmd/ai/skills/generator.d.ts +4 -0
- package/dist/cmd/ai/skills/generator.d.ts.map +1 -0
- package/dist/cmd/ai/skills/generator.js +402 -0
- package/dist/cmd/ai/skills/generator.js.map +1 -0
- package/dist/cmd/ai/skills/index.d.ts +4 -0
- package/dist/cmd/ai/skills/index.d.ts.map +1 -0
- package/dist/cmd/ai/skills/index.js +21 -0
- package/dist/cmd/ai/skills/index.js.map +1 -0
- package/dist/cmd/auth/signup.d.ts.map +1 -1
- package/dist/cmd/auth/signup.js +1 -0
- package/dist/cmd/auth/signup.js.map +1 -1
- package/dist/cmd/build/entry-generator.d.ts.map +1 -1
- package/dist/cmd/build/entry-generator.js +40 -5
- package/dist/cmd/build/entry-generator.js.map +1 -1
- package/dist/cmd/build/vite/bun-dev-server.d.ts +7 -1
- package/dist/cmd/build/vite/bun-dev-server.d.ts.map +1 -1
- package/dist/cmd/build/vite/bun-dev-server.js +52 -26
- package/dist/cmd/build/vite/bun-dev-server.js.map +1 -1
- package/dist/cmd/build/vite/metadata-generator.d.ts.map +1 -1
- package/dist/cmd/build/vite/metadata-generator.js +58 -7
- package/dist/cmd/build/vite/metadata-generator.js.map +1 -1
- package/dist/cmd/build/vite/prompt-generator.d.ts +23 -0
- package/dist/cmd/build/vite/prompt-generator.d.ts.map +1 -0
- package/dist/cmd/build/vite/prompt-generator.js +123 -0
- package/dist/cmd/build/vite/prompt-generator.js.map +1 -0
- package/dist/cmd/build/vite/registry-generator.d.ts.map +1 -1
- package/dist/cmd/build/vite/registry-generator.js +28 -11
- package/dist/cmd/build/vite/registry-generator.js.map +1 -1
- package/dist/cmd/build/vite/server-bundler.d.ts +4 -0
- package/dist/cmd/build/vite/server-bundler.d.ts.map +1 -1
- package/dist/cmd/build/vite/server-bundler.js +45 -16
- package/dist/cmd/build/vite/server-bundler.js.map +1 -1
- package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +1 -1
- package/dist/cmd/build/vite/vite-asset-server-config.js +4 -0
- package/dist/cmd/build/vite/vite-asset-server-config.js.map +1 -1
- package/dist/cmd/build/vite/vite-builder.d.ts.map +1 -1
- package/dist/cmd/build/vite/vite-builder.js +99 -87
- package/dist/cmd/build/vite/vite-builder.js.map +1 -1
- package/dist/cmd/cloud/deploy.d.ts.map +1 -1
- package/dist/cmd/cloud/deploy.js +78 -27
- package/dist/cmd/cloud/deploy.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/create-namespace.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/create-namespace.js +3 -1
- package/dist/cmd/cloud/keyvalue/create-namespace.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/delete-namespace.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/delete-namespace.js +3 -1
- package/dist/cmd/cloud/keyvalue/delete-namespace.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/delete.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/delete.js +3 -1
- package/dist/cmd/cloud/keyvalue/delete.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/set.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/set.js +4 -2
- package/dist/cmd/cloud/keyvalue/set.js.map +1 -1
- package/dist/cmd/cloud/stream/get.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/get.js +2 -13
- package/dist/cmd/cloud/stream/get.js.map +1 -1
- package/dist/cmd/cloud/vector/delete-namespace.d.ts +3 -0
- package/dist/cmd/cloud/vector/delete-namespace.d.ts.map +1 -0
- package/dist/cmd/cloud/vector/delete-namespace.js +77 -0
- package/dist/cmd/cloud/vector/delete-namespace.js.map +1 -0
- package/dist/cmd/cloud/vector/index.d.ts.map +1 -1
- package/dist/cmd/cloud/vector/index.js +21 -4
- package/dist/cmd/cloud/vector/index.js.map +1 -1
- package/dist/cmd/cloud/vector/list-namespaces.d.ts +3 -0
- package/dist/cmd/cloud/vector/list-namespaces.d.ts.map +1 -0
- package/dist/cmd/cloud/vector/list-namespaces.js +42 -0
- package/dist/cmd/cloud/vector/list-namespaces.js.map +1 -0
- package/dist/cmd/cloud/vector/stats.d.ts +3 -0
- package/dist/cmd/cloud/vector/stats.d.ts.map +1 -0
- package/dist/cmd/cloud/vector/stats.js +142 -0
- package/dist/cmd/cloud/vector/stats.js.map +1 -0
- package/dist/cmd/cloud/vector/upsert.d.ts +3 -0
- package/dist/cmd/cloud/vector/upsert.d.ts.map +1 -0
- package/dist/cmd/cloud/vector/upsert.js +192 -0
- package/dist/cmd/cloud/vector/upsert.js.map +1 -0
- package/dist/cmd/dev/file-watcher.d.ts.map +1 -1
- package/dist/cmd/dev/file-watcher.js +90 -31
- package/dist/cmd/dev/file-watcher.js.map +1 -1
- package/dist/cmd/dev/index.d.ts.map +1 -1
- package/dist/cmd/dev/index.js +213 -57
- package/dist/cmd/dev/index.js.map +1 -1
- package/dist/cmd/dev/skills.d.ts +10 -0
- package/dist/cmd/dev/skills.d.ts.map +1 -0
- package/dist/cmd/dev/skills.js +57 -0
- package/dist/cmd/dev/skills.js.map +1 -0
- package/dist/cmd/dev/sync.js +7 -7
- package/dist/cmd/dev/sync.js.map +1 -1
- package/dist/cmd/index.d.ts.map +1 -1
- package/dist/cmd/index.js +1 -0
- package/dist/cmd/index.js.map +1 -1
- package/dist/cmd/project/create.d.ts.map +1 -1
- package/dist/cmd/project/create.js +3 -0
- package/dist/cmd/project/create.js.map +1 -1
- package/dist/cmd/project/template-flow.d.ts +1 -0
- package/dist/cmd/project/template-flow.d.ts.map +1 -1
- package/dist/cmd/project/template-flow.js +30 -5
- package/dist/cmd/project/template-flow.js.map +1 -1
- package/dist/cmd/setup/index.d.ts.map +1 -1
- package/dist/cmd/setup/index.js +1 -0
- package/dist/cmd/setup/index.js.map +1 -1
- package/dist/cmd/upgrade/index.d.ts +15 -0
- package/dist/cmd/upgrade/index.d.ts.map +1 -1
- package/dist/cmd/upgrade/index.js +59 -4
- package/dist/cmd/upgrade/index.js.map +1 -1
- package/dist/domain.d.ts +45 -0
- package/dist/domain.d.ts.map +1 -0
- package/dist/domain.js +200 -0
- package/dist/domain.js.map +1 -0
- package/dist/schema-generator.d.ts +2 -0
- package/dist/schema-generator.d.ts.map +1 -1
- package/dist/schema-generator.js +18 -0
- package/dist/schema-generator.js.map +1 -1
- package/dist/steps.d.ts +1 -1
- package/dist/steps.d.ts.map +1 -1
- package/dist/steps.js +16 -5
- package/dist/steps.js.map +1 -1
- package/dist/tui/prompt.d.ts +1 -2
- package/dist/tui/prompt.d.ts.map +1 -1
- package/dist/tui/prompt.js +8 -4
- package/dist/tui/prompt.js.map +1 -1
- package/dist/tui.d.ts +16 -0
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +23 -2
- package/dist/tui.js.map +1 -1
- package/dist/types.d.ts +9 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -3
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
- package/src/cli.ts +47 -12
- package/src/cmd/ai/index.ts +6 -1
- package/src/cmd/ai/prompt/agent.md +306 -0
- package/src/cmd/ai/prompt/agent.ts +12 -322
- package/src/cmd/ai/prompt/api.md +360 -0
- package/src/cmd/ai/prompt/api.ts +13 -260
- package/src/cmd/ai/prompt/version.ts +61 -0
- package/src/cmd/ai/prompt/web.md +509 -0
- package/src/cmd/ai/prompt/web.ts +12 -282
- package/src/cmd/ai/skills/generate.ts +75 -0
- package/src/cmd/ai/skills/generator.ts +519 -0
- package/src/cmd/ai/skills/index.ts +23 -0
- package/src/cmd/auth/signup.ts +1 -0
- package/src/cmd/build/entry-generator.ts +43 -7
- package/src/cmd/build/vite/bun-dev-server.ts +57 -27
- package/src/cmd/build/vite/metadata-generator.ts +73 -7
- package/src/cmd/build/vite/prompt-generator.ts +169 -0
- package/src/cmd/build/vite/registry-generator.ts +33 -10
- package/src/cmd/build/vite/server-bundler.ts +53 -22
- package/src/cmd/build/vite/vite-asset-server-config.ts +5 -0
- package/src/cmd/build/vite/vite-builder.ts +107 -87
- package/src/cmd/cloud/deploy.ts +99 -31
- package/src/cmd/cloud/keyvalue/create-namespace.ts +3 -1
- package/src/cmd/cloud/keyvalue/delete-namespace.ts +3 -1
- package/src/cmd/cloud/keyvalue/delete.ts +3 -1
- package/src/cmd/cloud/keyvalue/set.ts +4 -2
- package/src/cmd/cloud/stream/get.ts +2 -9
- package/src/cmd/cloud/vector/delete-namespace.ts +89 -0
- package/src/cmd/cloud/vector/index.ts +21 -4
- package/src/cmd/cloud/vector/list-namespaces.ts +46 -0
- package/src/cmd/cloud/vector/stats.ts +160 -0
- package/src/cmd/cloud/vector/upsert.ts +216 -0
- package/src/cmd/dev/file-watcher.ts +101 -32
- package/src/cmd/dev/index.ts +304 -111
- package/src/cmd/dev/skills.ts +82 -0
- package/src/cmd/dev/sync.ts +7 -7
- package/src/cmd/index.ts +1 -0
- package/src/cmd/project/create.ts +3 -0
- package/src/cmd/project/template-flow.ts +37 -5
- package/src/cmd/setup/index.ts +1 -0
- package/src/cmd/upgrade/index.ts +68 -4
- package/src/domain.ts +273 -0
- package/src/schema-generator.ts +23 -0
- package/src/steps.ts +16 -5
- package/src/tui/prompt.ts +11 -5
- package/src/tui.ts +21 -2
- package/src/types/md.d.ts +8 -0
- package/src/types.ts +12 -3
- package/dist/cmd/cloud/domain.d.ts +0 -17
- package/dist/cmd/cloud/domain.d.ts.map +0 -1
- package/dist/cmd/cloud/domain.js +0 -79
- package/dist/cmd/cloud/domain.js.map +0 -1
- package/src/cmd/cloud/domain.ts +0 -100
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# Agents Folder Guide
|
|
2
|
+
|
|
3
|
+
This folder contains AI agents for your Agentuity application. Each agent is organized in its own subdirectory.
|
|
4
|
+
|
|
5
|
+
## Generated Types
|
|
6
|
+
|
|
7
|
+
The `src/generated/` folder contains auto-generated TypeScript files:
|
|
8
|
+
|
|
9
|
+
- `registry.ts` - Agent registry with strongly-typed agent definitions and schema types
|
|
10
|
+
- `routes.ts` - Route registry for API, WebSocket, and SSE endpoints
|
|
11
|
+
- `app.ts` - Application entry point (regenerated on every build)
|
|
12
|
+
|
|
13
|
+
**Important:** Never edit files in `src/generated/` - they are overwritten on every build.
|
|
14
|
+
|
|
15
|
+
Import generated types in your agents:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import type { HelloInput, HelloOutput } from '../generated/registry';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Directory Structure
|
|
22
|
+
|
|
23
|
+
Each agent folder must contain:
|
|
24
|
+
|
|
25
|
+
- **agent.ts** (required) - Agent definition with schema and handler
|
|
26
|
+
|
|
27
|
+
Example structure:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
src/agent/
|
|
31
|
+
├── hello/
|
|
32
|
+
│ └── agent.ts
|
|
33
|
+
├── process-data/
|
|
34
|
+
│ └── agent.ts
|
|
35
|
+
└── (generated files in src/generated/)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Note:** HTTP routes are defined separately in `src/api/` - see the API folder guide for details.
|
|
39
|
+
|
|
40
|
+
## Creating an Agent
|
|
41
|
+
|
|
42
|
+
### Basic Agent (agent.ts)
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { createAgent } from '@agentuity/runtime';
|
|
46
|
+
import { s } from '@agentuity/schema';
|
|
47
|
+
|
|
48
|
+
const agent = createAgent('my-agent', {
|
|
49
|
+
description: 'What this agent does',
|
|
50
|
+
schema: {
|
|
51
|
+
input: s.object({
|
|
52
|
+
name: s.string(),
|
|
53
|
+
age: s.number(),
|
|
54
|
+
}),
|
|
55
|
+
output: s.string(),
|
|
56
|
+
},
|
|
57
|
+
handler: async (ctx, input) => {
|
|
58
|
+
// Access context: ctx.app, ctx.config, ctx.logger, ctx.kv, ctx.vector, ctx.stream
|
|
59
|
+
return `Hello, ${input.name}! You are ${input.age} years old.`;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export default agent;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Agent with Lifecycle (setup/shutdown)
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { createAgent } from '@agentuity/runtime';
|
|
70
|
+
import { s } from '@agentuity/schema';
|
|
71
|
+
|
|
72
|
+
const agent = createAgent('lifecycle-agent', {
|
|
73
|
+
description: 'Agent with setup and shutdown',
|
|
74
|
+
schema: {
|
|
75
|
+
input: s.object({ message: s.string() }),
|
|
76
|
+
output: s.object({ result: s.string() }),
|
|
77
|
+
},
|
|
78
|
+
setup: async (app) => {
|
|
79
|
+
// Initialize resources (runs once on startup)
|
|
80
|
+
// app contains: appName, version, startedAt, config
|
|
81
|
+
return {
|
|
82
|
+
agentId: `agent-${Math.random().toString(36).substr(2, 9)}`,
|
|
83
|
+
connectionPool: ['conn-1', 'conn-2'],
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
handler: async (ctx, input) => {
|
|
87
|
+
// Access setup config via ctx.config (fully typed)
|
|
88
|
+
ctx.logger.info('Agent ID:', ctx.config.agentId);
|
|
89
|
+
ctx.logger.info('Connections:', ctx.config.connectionPool);
|
|
90
|
+
return { result: `Processed: ${input.message}` };
|
|
91
|
+
},
|
|
92
|
+
shutdown: async (app, config) => {
|
|
93
|
+
// Cleanup resources (runs on shutdown)
|
|
94
|
+
console.log('Shutting down agent:', config.agentId);
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export default agent;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Agent with Event Listeners
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { createAgent } from '@agentuity/runtime';
|
|
105
|
+
import { s } from '@agentuity/schema';
|
|
106
|
+
|
|
107
|
+
const agent = createAgent('event-agent', {
|
|
108
|
+
schema: {
|
|
109
|
+
input: s.object({ data: s.string() }),
|
|
110
|
+
output: s.string(),
|
|
111
|
+
},
|
|
112
|
+
handler: async (ctx, input) => {
|
|
113
|
+
return `Processed: ${input.data}`;
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
agent.addEventListener('started', (eventName, agent, ctx) => {
|
|
118
|
+
ctx.logger.info('Agent started');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
agent.addEventListener('completed', (eventName, agent, ctx) => {
|
|
122
|
+
ctx.logger.info('Agent completed');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
agent.addEventListener('errored', (eventName, agent, ctx, error) => {
|
|
126
|
+
ctx.logger.error('Agent errored:', error);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export default agent;
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Agent Context (ctx)
|
|
133
|
+
|
|
134
|
+
The handler receives a context object with:
|
|
135
|
+
|
|
136
|
+
- **ctx.app** - Application state (appName, version, startedAt, config from createApp)
|
|
137
|
+
- **ctx.config** - Agent-specific config (from setup return value, fully typed)
|
|
138
|
+
- **ctx.logger** - Structured logger (info, warn, error, debug, trace)
|
|
139
|
+
- **ctx.tracer** - OpenTelemetry tracer for custom spans
|
|
140
|
+
- **ctx.sessionId** - Unique session identifier
|
|
141
|
+
- **ctx.kv** - Key-value storage
|
|
142
|
+
- **ctx.vector** - Vector storage for embeddings
|
|
143
|
+
- **ctx.stream** - Stream storage for real-time data
|
|
144
|
+
- **ctx.state** - In-memory request-scoped state (Map)
|
|
145
|
+
- **ctx.thread** - Thread information for multi-turn conversations
|
|
146
|
+
- **ctx.session** - Session information
|
|
147
|
+
- **ctx.waitUntil** - Schedule background tasks
|
|
148
|
+
|
|
149
|
+
## Examples
|
|
150
|
+
|
|
151
|
+
### Using Key-Value Storage
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
handler: async (ctx, input) => {
|
|
155
|
+
await ctx.kv.set('user:123', { name: 'Alice', age: 30 });
|
|
156
|
+
const user = await ctx.kv.get('user:123');
|
|
157
|
+
await ctx.kv.delete('user:123');
|
|
158
|
+
const keys = await ctx.kv.list('user:*');
|
|
159
|
+
return user;
|
|
160
|
+
};
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Using Vector Storage
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
handler: async (ctx, input) => {
|
|
167
|
+
await ctx.vector.upsert('docs', [
|
|
168
|
+
{ id: '1', values: [0.1, 0.2, 0.3], metadata: { text: 'Hello' } },
|
|
169
|
+
]);
|
|
170
|
+
const results = await ctx.vector.query('docs', [0.1, 0.2, 0.3], { topK: 5 });
|
|
171
|
+
return results;
|
|
172
|
+
};
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Using Streams
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
handler: async (ctx, input) => {
|
|
179
|
+
const stream = await ctx.stream.create('agent-logs');
|
|
180
|
+
await ctx.stream.write(stream.id, 'Processing step 1');
|
|
181
|
+
await ctx.stream.write(stream.id, 'Processing step 2');
|
|
182
|
+
return { streamId: stream.id };
|
|
183
|
+
};
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Background Tasks with waitUntil
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
handler: async (ctx, input) => {
|
|
190
|
+
// Schedule background work that continues after response
|
|
191
|
+
ctx.waitUntil(async () => {
|
|
192
|
+
await ctx.kv.set('processed', Date.now());
|
|
193
|
+
ctx.logger.info('Background task complete');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
return { status: 'processing' };
|
|
197
|
+
};
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Calling Another Agent
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
// Import the agent directly
|
|
204
|
+
import otherAgent from '../other-agent/agent';
|
|
205
|
+
|
|
206
|
+
handler: async (ctx, input) => {
|
|
207
|
+
const result = await otherAgent.run({ data: input.value });
|
|
208
|
+
return `Other agent returned: ${result}`;
|
|
209
|
+
};
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Subagents (Nested Agents)
|
|
213
|
+
|
|
214
|
+
Agents can have subagents organized one level deep. This is useful for grouping related functionality.
|
|
215
|
+
|
|
216
|
+
### Directory Structure for Subagents
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
src/agent/
|
|
220
|
+
└── team/ # Parent agent
|
|
221
|
+
├── agent.ts # Parent agent
|
|
222
|
+
├── members/ # Subagent
|
|
223
|
+
│ └── agent.ts
|
|
224
|
+
└── tasks/ # Subagent
|
|
225
|
+
└── agent.ts
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Parent Agent
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import { createAgent } from '@agentuity/runtime';
|
|
232
|
+
import { s } from '@agentuity/schema';
|
|
233
|
+
|
|
234
|
+
const agent = createAgent('team', {
|
|
235
|
+
description: 'Team Manager',
|
|
236
|
+
schema: {
|
|
237
|
+
input: s.object({ action: s.union([s.literal('info'), s.literal('count')]) }),
|
|
238
|
+
output: s.object({
|
|
239
|
+
message: s.string(),
|
|
240
|
+
timestamp: s.string(),
|
|
241
|
+
}),
|
|
242
|
+
},
|
|
243
|
+
handler: async (ctx, { action }) => {
|
|
244
|
+
return {
|
|
245
|
+
message: 'Team parent agent - manages members and tasks',
|
|
246
|
+
timestamp: new Date().toISOString(),
|
|
247
|
+
};
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
export default agent;
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Subagent (Accessing Parent)
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { createAgent } from '@agentuity/runtime';
|
|
258
|
+
import { s } from '@agentuity/schema';
|
|
259
|
+
import parentAgent from '../agent';
|
|
260
|
+
|
|
261
|
+
const agent = createAgent('team.members', {
|
|
262
|
+
description: 'Members Subagent',
|
|
263
|
+
schema: {
|
|
264
|
+
input: s.object({
|
|
265
|
+
action: s.union([s.literal('list'), s.literal('add'), s.literal('remove')]),
|
|
266
|
+
name: s.optional(s.string()),
|
|
267
|
+
}),
|
|
268
|
+
output: s.object({
|
|
269
|
+
members: s.array(s.string()),
|
|
270
|
+
parentInfo: s.optional(s.string()),
|
|
271
|
+
}),
|
|
272
|
+
},
|
|
273
|
+
handler: async (ctx, { action, name }) => {
|
|
274
|
+
// Call parent agent directly
|
|
275
|
+
const parentResult = await parentAgent.run({ action: 'info' });
|
|
276
|
+
const parentInfo = `Parent says: ${parentResult.message}`;
|
|
277
|
+
|
|
278
|
+
let members = ['Alice', 'Bob'];
|
|
279
|
+
if (action === 'add' && name) {
|
|
280
|
+
members.push(name);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return { members, parentInfo };
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
export default agent;
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Key Points About Subagents
|
|
291
|
+
|
|
292
|
+
- **One level deep**: Only one level of nesting is supported (no nested subagents)
|
|
293
|
+
- **Access parent**: Import and call parent agents directly
|
|
294
|
+
- **Agent names**: Subagents have dotted names like `"team.members"`
|
|
295
|
+
- **Shared context**: Subagents share the same app context (kv, logger, etc.)
|
|
296
|
+
|
|
297
|
+
## Rules
|
|
298
|
+
|
|
299
|
+
- Each agent folder name becomes the agent's route name (e.g., `hello/` → `/agent/hello`)
|
|
300
|
+
- **agent.ts** must export default the agent instance
|
|
301
|
+
- The first argument to `createAgent()` is the agent name (must match folder structure)
|
|
302
|
+
- Input/output schemas are enforced with @agentuity/schema validation
|
|
303
|
+
- Setup return value type automatically flows to ctx.config (fully typed)
|
|
304
|
+
- Use ctx.logger for logging, not console.log
|
|
305
|
+
- Import agents directly to call them (recommended approach)
|
|
306
|
+
- Subagents are one level deep only (team/members/, not team/members/subagent/)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createSubcommand } from '../../../types';
|
|
2
2
|
import type { CommandContext } from '../../../types';
|
|
3
3
|
import { getCommand } from '../../../command-prefix';
|
|
4
|
+
import { appendHashComment } from './version';
|
|
5
|
+
import agentPromptContent from './agent.md' with { type: 'text' };
|
|
4
6
|
|
|
5
7
|
export const agentSubcommand = createSubcommand({
|
|
6
8
|
name: 'agent',
|
|
@@ -14,328 +16,16 @@ export const agentSubcommand = createSubcommand({
|
|
|
14
16
|
},
|
|
15
17
|
});
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## Directory Structure
|
|
23
|
-
|
|
24
|
-
Each agent folder must contain:
|
|
25
|
-
- **agent.ts** (required) - Agent definition with metadata, schema, and handler
|
|
26
|
-
- **route.ts** (optional) - HTTP routes for the agent endpoint
|
|
27
|
-
|
|
28
|
-
Example structure:
|
|
29
|
-
\`\`\`
|
|
30
|
-
src/agent/
|
|
31
|
-
├── hello/
|
|
32
|
-
│ ├── agent.ts
|
|
33
|
-
│ └── route.ts
|
|
34
|
-
├── process-data/
|
|
35
|
-
│ ├── agent.ts
|
|
36
|
-
│ └── route.ts
|
|
37
|
-
└── registry.generated.ts (auto-generated)
|
|
38
|
-
\`\`\`
|
|
39
|
-
|
|
40
|
-
## Creating an Agent
|
|
41
|
-
|
|
42
|
-
### Basic Agent (agent.ts)
|
|
43
|
-
|
|
44
|
-
\`\`\`typescript
|
|
45
|
-
import { createAgent } from '@agentuity/runtime';
|
|
46
|
-
import { s } from '@agentuity/schema';
|
|
47
|
-
|
|
48
|
-
const agent = createAgent({
|
|
49
|
-
metadata: {
|
|
50
|
-
name: 'My Agent',
|
|
51
|
-
description: 'What this agent does',
|
|
52
|
-
},
|
|
53
|
-
schema: {
|
|
54
|
-
input: s.object({
|
|
55
|
-
name: s.string(),
|
|
56
|
-
age: s.number()
|
|
57
|
-
}),
|
|
58
|
-
output: s.string(),
|
|
59
|
-
},
|
|
60
|
-
handler: async (c, input) => {
|
|
61
|
-
// Access context: c.app, c.config, c.logger, c.kv, c.vector, c.stream
|
|
62
|
-
return \`Hello, \${input.name}! You are \${input.age} years old.\`;
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
export default agent;
|
|
67
|
-
\`\`\`
|
|
68
|
-
|
|
69
|
-
### Agent with Lifecycle (setup/shutdown)
|
|
70
|
-
|
|
71
|
-
\`\`\`typescript
|
|
72
|
-
import { createAgent, type AppState } from '@agentuity/runtime';
|
|
73
|
-
import { s } from '@agentuity/schema';
|
|
74
|
-
|
|
75
|
-
const agent = createAgent({
|
|
76
|
-
metadata: {
|
|
77
|
-
name: 'Lifecycle Agent',
|
|
78
|
-
description: 'Agent with setup and shutdown',
|
|
79
|
-
},
|
|
80
|
-
schema: {
|
|
81
|
-
input: s.object({ message: s.string() }),
|
|
82
|
-
output: s.object({ result: s.string() }),
|
|
83
|
-
},
|
|
84
|
-
setup: async (app: AppState) => {
|
|
85
|
-
// Initialize resources (runs once on startup)
|
|
86
|
-
console.log('Setting up agent for app:', app.appName);
|
|
87
|
-
return {
|
|
88
|
-
agentId: \`agent-\${Math.random().toString(36).substr(2, 9)}\`,
|
|
89
|
-
connectionPool: ['conn-1', 'conn-2'],
|
|
90
|
-
};
|
|
91
|
-
},
|
|
92
|
-
handler: async (ctx, input) => {
|
|
93
|
-
// Access setup config via ctx.config (fully typed)
|
|
94
|
-
console.log('Agent ID:', ctx.config.agentId);
|
|
95
|
-
console.log('Connections:', ctx.config.connectionPool);
|
|
96
|
-
return { result: \`Processed: \${input.message}\` };
|
|
97
|
-
},
|
|
98
|
-
shutdown: async (app, config) => {
|
|
99
|
-
// Cleanup resources (runs on shutdown)
|
|
100
|
-
console.log('Shutting down agent:', config.agentId);
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
export default agent;
|
|
105
|
-
\`\`\`
|
|
106
|
-
|
|
107
|
-
### Agent with Event Listeners
|
|
108
|
-
|
|
109
|
-
\`\`\`typescript
|
|
110
|
-
const agent = createAgent({
|
|
111
|
-
// ... configuration
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
agent.addEventListener('started', (eventName, agent, ctx) => {
|
|
115
|
-
console.log('Agent started:', ctx.config.agentId);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
agent.addEventListener('completed', (eventName, agent, ctx) => {
|
|
119
|
-
console.log('Agent completed');
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
export default agent;
|
|
123
|
-
\`\`\`
|
|
124
|
-
|
|
125
|
-
## Creating Routes (route.ts)
|
|
126
|
-
|
|
127
|
-
Routes expose HTTP endpoints for your agent:
|
|
128
|
-
|
|
129
|
-
\`\`\`typescript
|
|
130
|
-
import { createRouter } from '@agentuity/runtime';
|
|
131
|
-
import agent from './agent';
|
|
132
|
-
|
|
133
|
-
const router = createRouter();
|
|
134
|
-
|
|
135
|
-
// GET /agent/hello
|
|
136
|
-
router.get('/', async (c) => {
|
|
137
|
-
const result = await c.agent.hello.run({ name: 'World', age: 25 });
|
|
138
|
-
return c.text(result);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// POST /agent/hello with validation
|
|
142
|
-
router.post('/', agent.validator(), async (c) => {
|
|
143
|
-
const data = c.req.valid('json');
|
|
144
|
-
const result = await c.agent.hello.run(data);
|
|
145
|
-
return c.text(result);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
export default router;
|
|
149
|
-
\`\`\`
|
|
150
|
-
|
|
151
|
-
## Agent Context (c)
|
|
152
|
-
|
|
153
|
-
The handler receives a context object with:
|
|
154
|
-
|
|
155
|
-
- **c.app** - Application state (appName, version, startedAt, config)
|
|
156
|
-
- **c.config** - Agent-specific config (from setup return value, fully typed)
|
|
157
|
-
- **c.logger** - Structured logger (info, warn, error, debug, trace)
|
|
158
|
-
- **c.kv** - Key-value storage
|
|
159
|
-
- **c.vector** - Vector storage
|
|
160
|
-
- **c.stream** - Stream management (create, list, delete)
|
|
161
|
-
- **c.agent** - Access to other agents (c.agent.otherAgent.run())
|
|
162
|
-
|
|
163
|
-
## Context in Routes (c)
|
|
164
|
-
|
|
165
|
-
Route handlers have additional context:
|
|
166
|
-
|
|
167
|
-
- **c.req** - Hono request object
|
|
168
|
-
- **c.var.logger** - Logger instance
|
|
169
|
-
- **Import agents directly** - Import and call agents directly instead of using c.var.agent
|
|
170
|
-
|
|
171
|
-
## Examples
|
|
172
|
-
|
|
173
|
-
### Using Key-Value Storage
|
|
174
|
-
|
|
175
|
-
\`\`\`typescript
|
|
176
|
-
handler: async (c, input) => {
|
|
177
|
-
await c.kv.set('user:123', { name: 'Alice', age: 30 });
|
|
178
|
-
const user = await c.kv.get('user:123');
|
|
179
|
-
return user;
|
|
180
|
-
}
|
|
181
|
-
\`\`\`
|
|
182
|
-
|
|
183
|
-
### Using Streams
|
|
184
|
-
|
|
185
|
-
\`\`\`typescript
|
|
186
|
-
handler: async (c, input) => {
|
|
187
|
-
const stream = await c.stream.create('output', {
|
|
188
|
-
metadata: { createdBy: 'my-agent' },
|
|
189
|
-
contentType: 'text/plain',
|
|
190
|
-
});
|
|
191
|
-
await stream.write('Hello from stream');
|
|
192
|
-
await stream.close();
|
|
193
|
-
return { streamId: stream.id, url: stream.url };
|
|
194
|
-
}
|
|
195
|
-
\`\`\`
|
|
196
|
-
|
|
197
|
-
### Calling Another Agent
|
|
198
|
-
|
|
199
|
-
\`\`\`typescript
|
|
200
|
-
handler: async (c, input) => {
|
|
201
|
-
const result = await c.agent.otherAgent.run({ data: input.value });
|
|
202
|
-
return \`Other agent returned: \${result}\`;
|
|
19
|
+
/**
|
|
20
|
+
* Get the raw prompt content without hash.
|
|
21
|
+
*/
|
|
22
|
+
export function getPromptContent(): string {
|
|
23
|
+
return agentPromptContent;
|
|
203
24
|
}
|
|
204
|
-
\`\`\`
|
|
205
|
-
|
|
206
|
-
## Subagents (Nested Agents)
|
|
207
|
-
|
|
208
|
-
Agents can have subagents organized one level deep. This is useful for grouping related functionality.
|
|
209
|
-
|
|
210
|
-
### Directory Structure for Subagents
|
|
211
|
-
|
|
212
|
-
\`\`\`
|
|
213
|
-
src/agent/
|
|
214
|
-
└── team/ # Parent agent
|
|
215
|
-
├── agent.ts # Parent agent
|
|
216
|
-
├── route.ts # Parent routes
|
|
217
|
-
├── members/ # Subagent
|
|
218
|
-
│ ├── agent.ts
|
|
219
|
-
│ └── route.ts
|
|
220
|
-
└── tasks/ # Subagent
|
|
221
|
-
├── agent.ts
|
|
222
|
-
└── route.ts
|
|
223
|
-
\`\`\`
|
|
224
|
-
|
|
225
|
-
### Parent Agent
|
|
226
|
-
|
|
227
|
-
\`\`\`typescript
|
|
228
|
-
import { createAgent } from '@agentuity/runtime';
|
|
229
|
-
import { s } from '@agentuity/schema';
|
|
230
|
-
|
|
231
|
-
const agent = createAgent({
|
|
232
|
-
metadata: {
|
|
233
|
-
name: 'Team Manager',
|
|
234
|
-
},
|
|
235
|
-
schema: {
|
|
236
|
-
input: s.object({ action: s.union([s.literal('info'), s.literal('count')]) }),
|
|
237
|
-
output: s.object({
|
|
238
|
-
message: s.string(),
|
|
239
|
-
timestamp: s.string()
|
|
240
|
-
}),
|
|
241
|
-
},
|
|
242
|
-
handler: async (ctx, { action }) => {
|
|
243
|
-
return {
|
|
244
|
-
message: 'Team parent agent - manages members and tasks',
|
|
245
|
-
timestamp: new Date().toISOString(),
|
|
246
|
-
};
|
|
247
|
-
},
|
|
248
|
-
});
|
|
249
25
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
\`\`\`typescript
|
|
256
|
-
import { createAgent } from '@agentuity/runtime';
|
|
257
|
-
import { s } from '@agentuity/schema';
|
|
258
|
-
|
|
259
|
-
const agent = createAgent({
|
|
260
|
-
metadata: {
|
|
261
|
-
name: 'Members Subagent',
|
|
262
|
-
},
|
|
263
|
-
schema: {
|
|
264
|
-
input: s.object({
|
|
265
|
-
action: s.union([s.literal('list'), s.literal('add'), s.literal('remove')]),
|
|
266
|
-
name: s.optional(s.string()),
|
|
267
|
-
}),
|
|
268
|
-
output: s.object({
|
|
269
|
-
members: s.array(s.string()),
|
|
270
|
-
parentInfo: s.optional(s.string()),
|
|
271
|
-
}),
|
|
272
|
-
},
|
|
273
|
-
handler: async (ctx, { action, name }) => {
|
|
274
|
-
// Access parent agent
|
|
275
|
-
const parentResult = await ctx.agent.team.run({ action: 'info' });
|
|
276
|
-
const parentInfo = \`Parent says: \${parentResult.message}\`;
|
|
277
|
-
|
|
278
|
-
// Subagent logic here
|
|
279
|
-
let members = ['Alice', 'Bob'];
|
|
280
|
-
if (action === 'add' && name) {
|
|
281
|
-
members.push(name);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return { members, parentInfo };
|
|
285
|
-
},
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
export default agent;
|
|
289
|
-
\`\`\`
|
|
290
|
-
|
|
291
|
-
### Accessing Subagents from Routes
|
|
292
|
-
|
|
293
|
-
\`\`\`typescript
|
|
294
|
-
import { createRouter } from '@agentuity/runtime';
|
|
295
|
-
|
|
296
|
-
const router = createRouter();
|
|
297
|
-
|
|
298
|
-
router.get('/', async (c) => {
|
|
299
|
-
// Call parent agent
|
|
300
|
-
const teamInfo = await c.agent.team.run({ action: 'info' });
|
|
301
|
-
|
|
302
|
-
// Call subagents (nested access)
|
|
303
|
-
const members = await c.agent.team.members.run({ action: 'list' });
|
|
304
|
-
const tasks = await c.agent.team.tasks.run({ action: 'list' });
|
|
305
|
-
|
|
306
|
-
return c.json({ teamInfo, members, tasks });
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
export default router;
|
|
310
|
-
\`\`\`
|
|
311
|
-
|
|
312
|
-
### Subagent Routes
|
|
313
|
-
|
|
314
|
-
Routes for subagents automatically mount under the parent path:
|
|
315
|
-
|
|
316
|
-
- Parent: \`/agent/team\`
|
|
317
|
-
- Subagent: \`/agent/team/members\`
|
|
318
|
-
- Subagent: \`/agent/team/tasks\`
|
|
319
|
-
|
|
320
|
-
### Key Points About Subagents
|
|
321
|
-
|
|
322
|
-
- **One level deep**: Only one level of nesting is supported (no nested subagents)
|
|
323
|
-
- **Access parent**: Subagents can call their parent via \`ctx.agent.parentName.run()\`
|
|
324
|
-
- **Agent names**: Subagents have dotted names like \`"team.members"\`
|
|
325
|
-
- **Route hierarchy**: Routes inherit parent path structure
|
|
326
|
-
- **Shared context**: Subagents share the same app context (kv, logger, etc.)
|
|
327
|
-
|
|
328
|
-
## Rules
|
|
329
|
-
|
|
330
|
-
- Each agent folder name becomes the agent's route name (e.g., \`hello/\` → \`/agent/hello\`)
|
|
331
|
-
- **agent.ts** must export default the agent instance
|
|
332
|
-
- **route.ts** must export default the router instance
|
|
333
|
-
- Input/output schemas are enforced with @agentuity/schema validation
|
|
334
|
-
- Setup return value type automatically flows to ctx.config (fully typed)
|
|
335
|
-
- Use c.logger for logging, not console.log
|
|
336
|
-
- Agent names in routes are accessed via c.agent.{folderName}
|
|
337
|
-
- Subagents are one level deep only (team/members/, not team/members/subagent/)
|
|
338
|
-
- Subagent routes mount under parent path (/agent/team/members)
|
|
339
|
-
- Agents do not necessary need a route.ts file if they aren't exposed externally
|
|
340
|
-
`;
|
|
26
|
+
/**
|
|
27
|
+
* Generate the agent prompt with hash comment.
|
|
28
|
+
*/
|
|
29
|
+
export function generateLLMPrompt(): string {
|
|
30
|
+
return appendHashComment(agentPromptContent);
|
|
341
31
|
}
|