@townco/agent 0.1.123 → 0.1.125
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/dist/acp-server/session-storage.js +25 -0
- package/dist/runner/langchain/tools/subagent-connections.d.ts +2 -0
- package/dist/runner/langchain/tools/subagent.js +13 -6
- package/dist/templates/index.d.ts +8 -0
- package/dist/templates/index.js +43 -14
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/templates/index.ts +63 -20
- package/dist/runner/langchain/tools/conversation_search.d.ts +0 -22
- package/dist/runner/langchain/tools/conversation_search.js +0 -137
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@townco/agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.125",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"files": [
|
|
@@ -83,12 +83,12 @@
|
|
|
83
83
|
"@opentelemetry/sdk-trace-base": "^1.28.0",
|
|
84
84
|
"@opentelemetry/sdk-trace-node": "^1.28.0",
|
|
85
85
|
"@opentelemetry/semantic-conventions": "^1.28.0",
|
|
86
|
-
"@townco/apiclient": "0.0.
|
|
87
|
-
"@townco/core": "0.0.
|
|
88
|
-
"@townco/gui-template": "0.1.
|
|
89
|
-
"@townco/tsconfig": "0.1.
|
|
90
|
-
"@townco/tui-template": "0.1.
|
|
91
|
-
"@townco/ui": "0.1.
|
|
86
|
+
"@townco/apiclient": "0.0.37",
|
|
87
|
+
"@townco/core": "0.0.95",
|
|
88
|
+
"@townco/gui-template": "0.1.114",
|
|
89
|
+
"@townco/tsconfig": "0.1.114",
|
|
90
|
+
"@townco/tui-template": "0.1.114",
|
|
91
|
+
"@townco/ui": "0.1.117",
|
|
92
92
|
"ai-tokenizer": "^1.0.6",
|
|
93
93
|
"exa-js": "^2.0.0",
|
|
94
94
|
"hono": "^4.10.4",
|
package/templates/index.ts
CHANGED
|
@@ -4,6 +4,14 @@ import type { AgentDefinition, McpConfigSchema } from "../definition";
|
|
|
4
4
|
|
|
5
5
|
type McpConfig = z.infer<typeof McpConfigSchema>;
|
|
6
6
|
|
|
7
|
+
/** Config for a subagent to wire up via makeSubagentsTool */
|
|
8
|
+
export interface SubagentConfig {
|
|
9
|
+
agentName: string;
|
|
10
|
+
toolDescription: string;
|
|
11
|
+
displayName?: string;
|
|
12
|
+
path: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
export interface TemplateVars {
|
|
8
16
|
name: string;
|
|
9
17
|
model: string;
|
|
@@ -24,6 +32,7 @@ export interface TemplateVars {
|
|
|
24
32
|
}
|
|
25
33
|
>;
|
|
26
34
|
mcps?: McpConfig[];
|
|
35
|
+
subagents?: SubagentConfig[];
|
|
27
36
|
systemPrompt: string | null;
|
|
28
37
|
hasWebSearch: boolean;
|
|
29
38
|
hasGenerateImage: boolean;
|
|
@@ -83,6 +92,14 @@ export function getTemplateVars(
|
|
|
83
92
|
result.mcps = definition.mcps;
|
|
84
93
|
}
|
|
85
94
|
|
|
95
|
+
// Handle subagents if defined (using type assertion since AgentDefinition may not have subagents yet)
|
|
96
|
+
const defWithSubagents = definition as AgentDefinition & {
|
|
97
|
+
subagents?: SubagentConfig[];
|
|
98
|
+
};
|
|
99
|
+
if (defWithSubagents.subagents && defWithSubagents.subagents.length > 0) {
|
|
100
|
+
result.subagents = defWithSubagents.subagents;
|
|
101
|
+
}
|
|
102
|
+
|
|
86
103
|
return result;
|
|
87
104
|
}
|
|
88
105
|
|
|
@@ -123,41 +140,67 @@ export function generatePackageJson(vars: TemplateVars): string {
|
|
|
123
140
|
}
|
|
124
141
|
|
|
125
142
|
export async function generateIndexTs(vars: TemplateVars): Promise<string> {
|
|
126
|
-
|
|
127
|
-
const agentDef: Record<string, unknown> = {
|
|
128
|
-
model: vars.model,
|
|
129
|
-
};
|
|
143
|
+
const hasSubagents = vars.subagents && vars.subagents.length > 0;
|
|
130
144
|
|
|
145
|
+
let imports =
|
|
146
|
+
'import type { AgentDefinition } from "@townco/agent/definition";';
|
|
147
|
+
if (hasSubagents) {
|
|
148
|
+
imports += '\nimport { makeSubagentsTool } from "@townco/agent/utils";';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Build tools code - either plain JSON or with makeSubagentsTool call
|
|
152
|
+
const toolsCode: string = (() => {
|
|
153
|
+
if (!hasSubagents) {
|
|
154
|
+
return JSON.stringify(vars.tools);
|
|
155
|
+
}
|
|
156
|
+
// makeSubagentsTool expects 'description' not 'toolDescription'
|
|
157
|
+
const subagentConfigs = vars.subagents!.map((s) => ({
|
|
158
|
+
agentName: s.agentName,
|
|
159
|
+
description: s.toolDescription,
|
|
160
|
+
...(s.displayName && { displayName: s.displayName }),
|
|
161
|
+
path: s.path,
|
|
162
|
+
}));
|
|
163
|
+
const subagentToolCall = `makeSubagentsTool(${JSON.stringify(subagentConfigs, null, 2)})`;
|
|
164
|
+
const toolItems = vars.tools.map((t) => JSON.stringify(t));
|
|
165
|
+
toolItems.push(subagentToolCall);
|
|
166
|
+
return `[${toolItems.join(", ")}]`;
|
|
167
|
+
})();
|
|
168
|
+
|
|
169
|
+
// Build optional fields
|
|
170
|
+
const optionalFields: string[] = [];
|
|
131
171
|
if (vars.displayName) {
|
|
132
|
-
|
|
172
|
+
optionalFields.push(`displayName: ${JSON.stringify(vars.displayName)},`);
|
|
133
173
|
}
|
|
134
174
|
if (vars.description) {
|
|
135
|
-
|
|
175
|
+
optionalFields.push(`description: ${JSON.stringify(vars.description)},`);
|
|
136
176
|
}
|
|
137
177
|
if (vars.suggestedPrompts) {
|
|
138
|
-
|
|
178
|
+
optionalFields.push(
|
|
179
|
+
`suggestedPrompts: ${JSON.stringify(vars.suggestedPrompts)},`,
|
|
180
|
+
);
|
|
139
181
|
}
|
|
140
|
-
|
|
141
|
-
agentDef.systemPrompt = vars.systemPrompt;
|
|
142
|
-
agentDef.tools = vars.tools;
|
|
143
|
-
|
|
144
182
|
if (vars.mcps && vars.mcps.length > 0) {
|
|
145
|
-
|
|
183
|
+
optionalFields.push(`mcps: ${JSON.stringify(vars.mcps)},`);
|
|
146
184
|
}
|
|
147
|
-
|
|
148
185
|
if (vars.hooks) {
|
|
149
|
-
|
|
186
|
+
optionalFields.push(`hooks: ${JSON.stringify(vars.hooks)},`);
|
|
150
187
|
}
|
|
151
188
|
|
|
152
|
-
|
|
153
|
-
|
|
189
|
+
const optionalFieldsStr =
|
|
190
|
+
optionalFields.length > 0 ? `\n ${optionalFields.join("\n ")}` : "";
|
|
154
191
|
|
|
155
|
-
const
|
|
192
|
+
const code = `${imports}
|
|
193
|
+
|
|
194
|
+
const agent: AgentDefinition = {
|
|
195
|
+
model: ${JSON.stringify(vars.model)},${optionalFieldsStr}
|
|
196
|
+
systemPrompt: ${JSON.stringify(vars.systemPrompt)},
|
|
197
|
+
tools: ${toolsCode},
|
|
198
|
+
};
|
|
156
199
|
|
|
157
200
|
export default agent;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
);
|
|
201
|
+
`;
|
|
202
|
+
|
|
203
|
+
return prettier.format(code, { parser: "typescript" });
|
|
161
204
|
}
|
|
162
205
|
|
|
163
206
|
export function generateBinTs(): string {
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export declare const CONVERSATION_SEARCH_TOOL_NAME = "conversation_search";
|
|
3
|
-
/**
|
|
4
|
-
* Creates a conversation search tool that searches past agent chat sessions.
|
|
5
|
-
* @param agentDir - The directory of the current agent (e.g., agents/researcher)
|
|
6
|
-
*/
|
|
7
|
-
export declare function makeConversationSearchTool(agentDir: string): import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
8
|
-
query: z.ZodString;
|
|
9
|
-
date_from: z.ZodOptional<z.ZodString>;
|
|
10
|
-
date_to: z.ZodOptional<z.ZodString>;
|
|
11
|
-
max_results: z.ZodOptional<z.ZodNumber>;
|
|
12
|
-
}, z.core.$strip>, {
|
|
13
|
-
query: string;
|
|
14
|
-
date_from?: string | undefined;
|
|
15
|
-
date_to?: string | undefined;
|
|
16
|
-
max_results?: number | undefined;
|
|
17
|
-
}, {
|
|
18
|
-
query: string;
|
|
19
|
-
date_from?: string | undefined;
|
|
20
|
-
date_to?: string | undefined;
|
|
21
|
-
max_results?: number | undefined;
|
|
22
|
-
}, string>;
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { tool } from "langchain";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
export const CONVERSATION_SEARCH_TOOL_NAME = "conversation_search";
|
|
6
|
-
const conversationSearchSchema = z.object({
|
|
7
|
-
query: z
|
|
8
|
-
.string()
|
|
9
|
-
.min(1)
|
|
10
|
-
.describe("The text to search for in conversation messages (case-insensitive)"),
|
|
11
|
-
date_from: z
|
|
12
|
-
.string()
|
|
13
|
-
.optional()
|
|
14
|
-
.describe("ISO date string to filter conversations from this date onwards"),
|
|
15
|
-
date_to: z
|
|
16
|
-
.string()
|
|
17
|
-
.optional()
|
|
18
|
-
.describe("ISO date string to filter conversations up to this date"),
|
|
19
|
-
max_results: z
|
|
20
|
-
.number()
|
|
21
|
-
.optional()
|
|
22
|
-
.describe("Maximum number of matching conversations to return (default: 10)"),
|
|
23
|
-
});
|
|
24
|
-
/**
|
|
25
|
-
* Creates a conversation search tool that searches past agent chat sessions.
|
|
26
|
-
* @param agentDir - The directory of the current agent (e.g., agents/researcher)
|
|
27
|
-
*/
|
|
28
|
-
export function makeConversationSearchTool(agentDir) {
|
|
29
|
-
const conversationSearch = tool(async ({ query, date_from, date_to, max_results = 10 }) => {
|
|
30
|
-
const results = [];
|
|
31
|
-
const queryLower = query.toLowerCase();
|
|
32
|
-
const dateFromParsed = date_from ? new Date(date_from) : null;
|
|
33
|
-
const dateToParsed = date_to ? new Date(date_to) : null;
|
|
34
|
-
const sessionsDir = join(agentDir, ".sessions");
|
|
35
|
-
if (!existsSync(sessionsDir)) {
|
|
36
|
-
return `No conversations found matching "${query}".`;
|
|
37
|
-
}
|
|
38
|
-
let sessionFiles;
|
|
39
|
-
try {
|
|
40
|
-
sessionFiles = readdirSync(sessionsDir).filter((f) => f.endsWith(".json") && !f.endsWith(".tmp"));
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
return `No conversations found matching "${query}".`;
|
|
44
|
-
}
|
|
45
|
-
for (const file of sessionFiles) {
|
|
46
|
-
if (results.length >= max_results)
|
|
47
|
-
break;
|
|
48
|
-
try {
|
|
49
|
-
const content = readFileSync(join(sessionsDir, file), "utf-8");
|
|
50
|
-
const session = JSON.parse(content);
|
|
51
|
-
// Date filtering
|
|
52
|
-
const sessionDate = new Date(session.metadata.updatedAt);
|
|
53
|
-
if (dateFromParsed && sessionDate < dateFromParsed)
|
|
54
|
-
continue;
|
|
55
|
-
if (dateToParsed && sessionDate > dateToParsed)
|
|
56
|
-
continue;
|
|
57
|
-
// Search messages
|
|
58
|
-
const matches = [];
|
|
59
|
-
for (let i = 0; i < session.messages.length; i++) {
|
|
60
|
-
const msg = session.messages[i];
|
|
61
|
-
if (!msg)
|
|
62
|
-
continue;
|
|
63
|
-
const textBlocks = msg.content.filter((c) => c.type === "text");
|
|
64
|
-
for (const block of textBlocks) {
|
|
65
|
-
if (block.text.toLowerCase().includes(queryLower)) {
|
|
66
|
-
// Extract matched snippet with surrounding context
|
|
67
|
-
const matchIndex = block.text.toLowerCase().indexOf(queryLower);
|
|
68
|
-
const snippetStart = Math.max(0, matchIndex - 50);
|
|
69
|
-
const snippetEnd = Math.min(block.text.length, matchIndex + query.length + 50);
|
|
70
|
-
const matchedText = block.text.slice(snippetStart, snippetEnd);
|
|
71
|
-
matches.push({
|
|
72
|
-
messageIndex: i,
|
|
73
|
-
role: msg.role,
|
|
74
|
-
timestamp: msg.timestamp,
|
|
75
|
-
matchedText: (snippetStart > 0 ? "..." : "") +
|
|
76
|
-
matchedText +
|
|
77
|
-
(snippetEnd < block.text.length ? "..." : ""),
|
|
78
|
-
});
|
|
79
|
-
break; // One match per message is enough
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (matches.length > 0) {
|
|
84
|
-
results.push({
|
|
85
|
-
sessionId: session.sessionId,
|
|
86
|
-
agentName: session.metadata.agentName,
|
|
87
|
-
createdAt: session.metadata.createdAt,
|
|
88
|
-
updatedAt: session.metadata.updatedAt,
|
|
89
|
-
matches,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
// Skip invalid session files
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (results.length === 0) {
|
|
99
|
-
return `No conversations found matching "${query}".`;
|
|
100
|
-
}
|
|
101
|
-
// Format results as readable string
|
|
102
|
-
let output = `Found ${results.length} conversation(s) matching "${query}":\n\n`;
|
|
103
|
-
for (const result of results) {
|
|
104
|
-
output += `=== Session: ${result.sessionId} (${result.agentName}) ===\n`;
|
|
105
|
-
output += `Created: ${result.createdAt} | Updated: ${result.updatedAt}\n\n`;
|
|
106
|
-
for (const match of result.matches) {
|
|
107
|
-
output += `[Message ${match.messageIndex + 1} - ${match.role} @ ${match.timestamp}]\n`;
|
|
108
|
-
output += `"${match.matchedText}"\n\n`;
|
|
109
|
-
}
|
|
110
|
-
output += "---\n\n";
|
|
111
|
-
}
|
|
112
|
-
return output;
|
|
113
|
-
}, {
|
|
114
|
-
name: CONVERSATION_SEARCH_TOOL_NAME,
|
|
115
|
-
description: `Search across past chat conversations to find previous discussions on specific topics.
|
|
116
|
-
|
|
117
|
-
Use this tool to:
|
|
118
|
-
- Find previous conversations that discussed specific topics
|
|
119
|
-
- Recall information from past sessions
|
|
120
|
-
- Search for patterns or recurring themes across conversations
|
|
121
|
-
|
|
122
|
-
Parameters:
|
|
123
|
-
- query: The text to search for (case-insensitive)
|
|
124
|
-
- date_from: (optional) Only search conversations from this date onwards (ISO format, e.g., "2025-01-01")
|
|
125
|
-
- date_to: (optional) Only search conversations up to this date (ISO format)
|
|
126
|
-
- max_results: (optional) Maximum results to return (default: 10)`,
|
|
127
|
-
schema: conversationSearchSchema,
|
|
128
|
-
});
|
|
129
|
-
conversationSearch.prettyName = "Conversation Search";
|
|
130
|
-
conversationSearch.icon = "MessageSquare";
|
|
131
|
-
conversationSearch.verbiage = {
|
|
132
|
-
active: "Searching conversations for {query}",
|
|
133
|
-
past: "Searched conversations for {query}",
|
|
134
|
-
paramKey: "query",
|
|
135
|
-
};
|
|
136
|
-
return conversationSearch;
|
|
137
|
-
}
|