@townco/agent 0.1.24 → 0.1.26
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/adapter.d.ts +14 -10
- package/dist/acp-server/adapter.js +10 -0
- package/dist/acp-server/cli.d.ts +3 -1
- package/dist/acp-server/cli.js +9 -5
- package/dist/acp-server/http.d.ts +3 -1
- package/dist/bin.js +0 -0
- package/dist/definition/mcp.d.ts +0 -0
- package/dist/definition/mcp.js +0 -0
- package/dist/definition/tools/todo.d.ts +49 -0
- package/dist/definition/tools/todo.js +80 -0
- package/dist/definition/tools/web_search.d.ts +4 -0
- package/dist/definition/tools/web_search.js +26 -0
- package/dist/dev-agent/index.d.ts +2 -0
- package/dist/dev-agent/index.js +18 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.js +19 -0
- package/dist/index.js +4 -1
- package/dist/runner/agent-runner.d.ts +17 -1
- package/dist/runner/index.d.ts +3 -1
- package/dist/runner/index.js +18 -14
- package/dist/runner/langchain/index.js +74 -11
- package/dist/runner/langchain/tools/todo.d.ts +48 -32
- package/dist/runner/langchain/tools/web_search.d.ts +3 -1
- package/dist/runner/langchain/tools/web_search.js +3 -1
- package/dist/scaffold/templates/dot-claude/CLAUDE-append.md +30 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +4 -1
- package/package.json +5 -5
|
@@ -2,14 +2,18 @@ import * as acp from "@agentclientprotocol/sdk";
|
|
|
2
2
|
import type { AgentRunner } from "../runner";
|
|
3
3
|
/** Adapts an Agent to speak the ACP protocol */
|
|
4
4
|
export declare class AgentAcpAdapter implements acp.Agent {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
private connection;
|
|
6
|
+
private sessions;
|
|
7
|
+
private agent;
|
|
8
|
+
constructor(agent: AgentRunner, connection: acp.AgentSideConnection);
|
|
9
|
+
initialize(_params: acp.InitializeRequest): Promise<acp.InitializeResponse>;
|
|
10
|
+
newSession(_params: acp.NewSessionRequest): Promise<acp.NewSessionResponse>;
|
|
11
|
+
authenticate(
|
|
12
|
+
_params: acp.AuthenticateRequest,
|
|
13
|
+
): Promise<acp.AuthenticateResponse | undefined>;
|
|
14
|
+
setSessionMode(
|
|
15
|
+
_params: acp.SetSessionModeRequest,
|
|
16
|
+
): Promise<acp.SetSessionModeResponse>;
|
|
17
|
+
prompt(params: acp.PromptRequest): Promise<acp.PromptResponse>;
|
|
18
|
+
cancel(params: acp.CancelNotification): Promise<void>;
|
|
15
19
|
}
|
|
@@ -56,6 +56,16 @@ export class AgentAcpAdapter {
|
|
|
56
56
|
sessionId: params.sessionId,
|
|
57
57
|
messageId,
|
|
58
58
|
})) {
|
|
59
|
+
// Debug: log if this is an agent_message_chunk with tokenUsage in _meta
|
|
60
|
+
if ("sessionUpdate" in msg &&
|
|
61
|
+
msg.sessionUpdate === "agent_message_chunk") {
|
|
62
|
+
if ("_meta" in msg &&
|
|
63
|
+
msg._meta &&
|
|
64
|
+
typeof msg._meta === "object" &&
|
|
65
|
+
"tokenUsage" in msg._meta) {
|
|
66
|
+
console.error("DEBUG adapter: sending agent_message_chunk with tokenUsage in _meta:", JSON.stringify(msg._meta.tokenUsage));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
59
69
|
// The agent may emit extended types (like tool_output) that aren't in ACP SDK yet
|
|
60
70
|
// The http transport will handle routing these appropriately
|
|
61
71
|
this.connection.sessionUpdate({
|
package/dist/acp-server/cli.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { AgentDefinition } from "../definition";
|
|
2
2
|
import { type AgentRunner } from "../runner";
|
|
3
|
-
export declare function makeStdioTransport(
|
|
3
|
+
export declare function makeStdioTransport(
|
|
4
|
+
agent: AgentRunner | AgentDefinition,
|
|
5
|
+
): void;
|
package/dist/acp-server/cli.js
CHANGED
|
@@ -3,9 +3,13 @@ import * as acp from "@agentclientprotocol/sdk";
|
|
|
3
3
|
import { makeRunnerFromDefinition } from "../runner";
|
|
4
4
|
import { AgentAcpAdapter } from "./adapter";
|
|
5
5
|
export function makeStdioTransport(agent) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const agentRunner =
|
|
7
|
+
"definition" in agent ? agent : makeRunnerFromDefinition(agent);
|
|
8
|
+
const input = Writable.toWeb(process.stdout);
|
|
9
|
+
const output = Readable.toWeb(process.stdin);
|
|
10
|
+
const stream = acp.ndJsonStream(input, output);
|
|
11
|
+
new acp.AgentSideConnection(
|
|
12
|
+
(conn) => new AgentAcpAdapter(agentRunner, conn),
|
|
13
|
+
stream,
|
|
14
|
+
);
|
|
11
15
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { AgentDefinition } from "../definition";
|
|
2
2
|
import { type AgentRunner } from "../runner";
|
|
3
|
-
export declare function makeHttpTransport(
|
|
3
|
+
export declare function makeHttpTransport(
|
|
4
|
+
agent: AgentRunner | AgentDefinition,
|
|
5
|
+
): void;
|
package/dist/bin.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const todoItemSchema: z.ZodObject<
|
|
3
|
+
{
|
|
4
|
+
content: z.ZodString;
|
|
5
|
+
status: z.ZodEnum<{
|
|
6
|
+
pending: "pending";
|
|
7
|
+
in_progress: "in_progress";
|
|
8
|
+
completed: "completed";
|
|
9
|
+
}>;
|
|
10
|
+
activeForm: z.ZodString;
|
|
11
|
+
},
|
|
12
|
+
z.core.$strip
|
|
13
|
+
>;
|
|
14
|
+
export declare const todoWrite: import("langchain").DynamicStructuredTool<
|
|
15
|
+
z.ZodObject<
|
|
16
|
+
{
|
|
17
|
+
todos: z.ZodArray<
|
|
18
|
+
z.ZodObject<
|
|
19
|
+
{
|
|
20
|
+
content: z.ZodString;
|
|
21
|
+
status: z.ZodEnum<{
|
|
22
|
+
pending: "pending";
|
|
23
|
+
in_progress: "in_progress";
|
|
24
|
+
completed: "completed";
|
|
25
|
+
}>;
|
|
26
|
+
activeForm: z.ZodString;
|
|
27
|
+
},
|
|
28
|
+
z.core.$strip
|
|
29
|
+
>
|
|
30
|
+
>;
|
|
31
|
+
},
|
|
32
|
+
z.core.$strip
|
|
33
|
+
>,
|
|
34
|
+
{
|
|
35
|
+
todos: {
|
|
36
|
+
content: string;
|
|
37
|
+
status: "pending" | "in_progress" | "completed";
|
|
38
|
+
activeForm: string;
|
|
39
|
+
}[];
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
todos: {
|
|
43
|
+
content: string;
|
|
44
|
+
status: "pending" | "in_progress" | "completed";
|
|
45
|
+
activeForm: string;
|
|
46
|
+
}[];
|
|
47
|
+
},
|
|
48
|
+
string
|
|
49
|
+
>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { tool } from "langchain";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export const todoItemSchema = z.object({
|
|
4
|
+
content: z.string().min(1),
|
|
5
|
+
status: z.enum(["pending", "in_progress", "completed"]),
|
|
6
|
+
activeForm: z.string().min(1),
|
|
7
|
+
});
|
|
8
|
+
export const todoWrite = tool(
|
|
9
|
+
({ todos }) => {
|
|
10
|
+
// Simple implementation that confirms the todos were written
|
|
11
|
+
return `Successfully updated todo list with ${todos.length} items`;
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "todo_write",
|
|
15
|
+
description: `Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
|
|
16
|
+
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
17
|
+
|
|
18
|
+
## When to Use This Tool
|
|
19
|
+
Use this tool proactively in these scenarios:
|
|
20
|
+
|
|
21
|
+
1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
|
|
22
|
+
2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
|
|
23
|
+
3. User explicitly requests todo list - When the user directly asks you to use the todo list
|
|
24
|
+
4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
|
|
25
|
+
5. After receiving new instructions - Immediately capture user requirements as todos
|
|
26
|
+
6. When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
|
|
27
|
+
7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
|
|
28
|
+
|
|
29
|
+
## When NOT to Use This Tool
|
|
30
|
+
|
|
31
|
+
Skip using this tool when:
|
|
32
|
+
1. There is only a single, straightforward task
|
|
33
|
+
2. The task is trivial and tracking it provides no organizational benefit
|
|
34
|
+
3. The task can be completed in less than 3 trivial steps
|
|
35
|
+
4. The task is purely conversational or informational
|
|
36
|
+
|
|
37
|
+
NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
|
|
38
|
+
|
|
39
|
+
## Task States and Management
|
|
40
|
+
|
|
41
|
+
1. **Task States**: Use these states to track progress:
|
|
42
|
+
- pending: Task not yet started
|
|
43
|
+
- in_progress: Currently working on (limit to ONE task at a time)
|
|
44
|
+
- completed: Task finished successfully
|
|
45
|
+
|
|
46
|
+
**IMPORTANT**: Task descriptions must have two forms:
|
|
47
|
+
- content: The imperative form describing what needs to be done (e.g., "Run tests", "Build the project")
|
|
48
|
+
- activeForm: The present continuous form shown during execution (e.g., "Running tests", "Building the project")
|
|
49
|
+
|
|
50
|
+
2. **Task Management**:
|
|
51
|
+
- Update task status in real-time as you work
|
|
52
|
+
- Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
|
|
53
|
+
- Exactly ONE task must be in_progress at any time (not less, not more)
|
|
54
|
+
- Complete current tasks before starting new ones
|
|
55
|
+
- Remove tasks that are no longer relevant from the list entirely
|
|
56
|
+
|
|
57
|
+
3. **Task Completion Requirements**:
|
|
58
|
+
- ONLY mark a task as completed when you have FULLY accomplished it
|
|
59
|
+
- If you encounter errors, blockers, or cannot finish, keep the task as in_progress
|
|
60
|
+
- When blocked, create a new task describing what needs to be resolved
|
|
61
|
+
- Never mark a task as completed if:
|
|
62
|
+
- Tests are failing
|
|
63
|
+
- Implementation is partial
|
|
64
|
+
- You encountered unresolved errors
|
|
65
|
+
- You couldn't find necessary files or dependencies
|
|
66
|
+
|
|
67
|
+
4. **Task Breakdown**:
|
|
68
|
+
- Create specific, actionable items
|
|
69
|
+
- Break complex tasks into smaller, manageable steps
|
|
70
|
+
- Use clear, descriptive task names
|
|
71
|
+
- Always provide both forms:
|
|
72
|
+
- content: "Fix authentication bug"
|
|
73
|
+
- activeForm: "Fixing authentication bug"
|
|
74
|
+
|
|
75
|
+
When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.`,
|
|
76
|
+
schema: z.object({
|
|
77
|
+
todos: z.array(todoItemSchema),
|
|
78
|
+
}),
|
|
79
|
+
},
|
|
80
|
+
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ExaSearchResults } from "@langchain/exa";
|
|
2
|
+
import Exa from "exa-js";
|
|
3
|
+
|
|
4
|
+
let _webSearchInstance = null;
|
|
5
|
+
export function makeWebSearchTool() {
|
|
6
|
+
if (_webSearchInstance) {
|
|
7
|
+
return _webSearchInstance;
|
|
8
|
+
}
|
|
9
|
+
const apiKey = process.env.EXA_API_KEY;
|
|
10
|
+
if (!apiKey) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"EXA_API_KEY environment variable is required to use the web_search tool. " +
|
|
13
|
+
"Please set it to your Exa API key from https://exa.ai",
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const client = new Exa(apiKey);
|
|
17
|
+
_webSearchInstance = new ExaSearchResults({
|
|
18
|
+
client,
|
|
19
|
+
searchArgs: {
|
|
20
|
+
numResults: 5,
|
|
21
|
+
type: "auto",
|
|
22
|
+
text: true,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
return _webSearchInstance;
|
|
26
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { makeHttpTransport, makeStdioTransport } from "../acp-server/index";
|
|
5
|
+
// Load agent definition from JSON file
|
|
6
|
+
const configPath = join(import.meta.dir, "agent.json");
|
|
7
|
+
const agent = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
8
|
+
const transport = process.argv[2] || "stdio";
|
|
9
|
+
if (transport === "http") {
|
|
10
|
+
makeHttpTransport(agent);
|
|
11
|
+
}
|
|
12
|
+
else if (transport === "stdio") {
|
|
13
|
+
makeStdioTransport(agent);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
console.error(`Invalid transport: ${transport}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
package/dist/example.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { makeHttpTransport, makeStdioTransport } from "./acp-server/index.js";
|
|
3
|
+
|
|
4
|
+
const exampleAgent = {
|
|
5
|
+
model: "claude-sonnet-4-5-20250929",
|
|
6
|
+
systemPrompt: "You are a helpful assistant.",
|
|
7
|
+
tools: ["todo_write", "get_weather", "web_search"],
|
|
8
|
+
};
|
|
9
|
+
// Parse transport type from command line argument
|
|
10
|
+
const transport = process.argv[2] || "stdio";
|
|
11
|
+
if (transport === "http") {
|
|
12
|
+
makeHttpTransport(exampleAgent);
|
|
13
|
+
} else if (transport === "stdio") {
|
|
14
|
+
makeStdioTransport(exampleAgent);
|
|
15
|
+
} else {
|
|
16
|
+
console.error(`Invalid transport: ${transport}`);
|
|
17
|
+
console.error("Usage: bun run example.ts [stdio|http]");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,22 @@ export type CreateAgentRunnerParams = z.infer<typeof zAgentRunnerParams>;
|
|
|
32
32
|
export type InvokeRequest = Omit<PromptRequest, "_meta"> & {
|
|
33
33
|
messageId: string;
|
|
34
34
|
};
|
|
35
|
+
export interface TokenUsage {
|
|
36
|
+
inputTokens?: number;
|
|
37
|
+
outputTokens?: number;
|
|
38
|
+
totalTokens?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface AgentMessageChunkWithTokens {
|
|
41
|
+
sessionUpdate: "agent_message_chunk";
|
|
42
|
+
content: {
|
|
43
|
+
type: "text";
|
|
44
|
+
text: string;
|
|
45
|
+
};
|
|
46
|
+
_meta?: {
|
|
47
|
+
tokenUsage?: TokenUsage;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
35
51
|
export type ExtendedSessionUpdate = SessionNotification["update"] | {
|
|
36
52
|
sessionUpdate: "tool_output";
|
|
37
53
|
toolCallId: string;
|
|
@@ -43,7 +59,7 @@ export type ExtendedSessionUpdate = SessionNotification["update"] | {
|
|
|
43
59
|
_meta?: {
|
|
44
60
|
messageId?: string;
|
|
45
61
|
};
|
|
46
|
-
};
|
|
62
|
+
} | AgentMessageChunkWithTokens;
|
|
47
63
|
/** Describes an object that can run an agent definition */
|
|
48
64
|
export interface AgentRunner {
|
|
49
65
|
definition: CreateAgentRunnerParams;
|
package/dist/runner/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { AgentDefinition } from "../definition";
|
|
2
2
|
import { type AgentRunner } from "./agent-runner";
|
|
3
3
|
export type { AgentRunner };
|
|
4
|
-
export declare const makeRunnerFromDefinition: (
|
|
4
|
+
export declare const makeRunnerFromDefinition: (
|
|
5
|
+
definition: AgentDefinition,
|
|
6
|
+
) => AgentRunner;
|
package/dist/runner/index.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { zAgentRunnerParams } from "./agent-runner";
|
|
2
2
|
import { LangchainAgent } from "./langchain";
|
|
3
3
|
export const makeRunnerFromDefinition = (definition) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
const agentRunnerParams = zAgentRunnerParams.safeParse(definition);
|
|
5
|
+
if (!agentRunnerParams.success) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
`Invalid agent definition: ${agentRunnerParams.error.message}`,
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
switch (definition.harnessImplementation) {
|
|
11
|
+
case undefined:
|
|
12
|
+
case "langchain": {
|
|
13
|
+
return new LangchainAgent(agentRunnerParams.data);
|
|
14
|
+
}
|
|
15
|
+
default: {
|
|
16
|
+
const _exhaustiveCheck = definition.harnessImplementation;
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Unsupported harness implementation: ${definition.harnessImplementation}`,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
18
22
|
};
|
|
@@ -152,7 +152,6 @@ export class LangchainAgent {
|
|
|
152
152
|
totalTokens: msg.usage_metadata.total_tokens,
|
|
153
153
|
}
|
|
154
154
|
: undefined;
|
|
155
|
-
logger.debug("Token usage:", tokenUsage);
|
|
156
155
|
for (const toolCall of msg.tool_calls ?? []) {
|
|
157
156
|
if (toolCall.id == null) {
|
|
158
157
|
throw new Error(`Tool call is missing id: ${JSON.stringify(toolCall)}`);
|
|
@@ -206,25 +205,89 @@ export class LangchainAgent {
|
|
|
206
205
|
else if (streamMode === "messages") {
|
|
207
206
|
const aiMessage = chunk[0];
|
|
208
207
|
if (aiMessage instanceof AIMessageChunk) {
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
// Extract token usage metadata if available
|
|
209
|
+
const messageTokenUsage = aiMessage.usage_metadata
|
|
210
|
+
? {
|
|
211
|
+
inputTokens: aiMessage.usage_metadata.input_tokens,
|
|
212
|
+
outputTokens: aiMessage.usage_metadata.output_tokens,
|
|
213
|
+
totalTokens: aiMessage.usage_metadata.total_tokens,
|
|
214
|
+
}
|
|
215
|
+
: undefined;
|
|
216
|
+
if (messageTokenUsage) {
|
|
217
|
+
const contentType = typeof aiMessage.content;
|
|
218
|
+
const contentIsArray = Array.isArray(aiMessage.content);
|
|
219
|
+
const contentLength = contentIsArray
|
|
220
|
+
? aiMessage.content.length
|
|
221
|
+
: typeof aiMessage.content === "string"
|
|
222
|
+
? aiMessage.content.length
|
|
223
|
+
: -1;
|
|
224
|
+
console.error("DEBUG agent: messageTokenUsage:", JSON.stringify(messageTokenUsage), "contentType:", contentType, "isArray:", contentIsArray, "length:", contentLength);
|
|
225
|
+
}
|
|
226
|
+
// If we have tokenUsage but no content, send a token-only chunk
|
|
227
|
+
if (messageTokenUsage &&
|
|
228
|
+
(typeof aiMessage.content === "string"
|
|
229
|
+
? aiMessage.content === ""
|
|
230
|
+
: Array.isArray(aiMessage.content) &&
|
|
231
|
+
aiMessage.content.length === 0)) {
|
|
232
|
+
console.error("DEBUG agent: sending token-only chunk:", JSON.stringify(messageTokenUsage));
|
|
233
|
+
const msgToYield = {
|
|
211
234
|
sessionUpdate: "agent_message_chunk",
|
|
212
235
|
content: {
|
|
213
236
|
type: "text",
|
|
214
|
-
text:
|
|
237
|
+
text: "", // Empty text, just carrying tokenUsage
|
|
238
|
+
},
|
|
239
|
+
_meta: {
|
|
240
|
+
tokenUsage: messageTokenUsage,
|
|
215
241
|
},
|
|
216
242
|
};
|
|
243
|
+
yield msgToYield;
|
|
244
|
+
continue; // Skip the rest of the processing for this chunk
|
|
245
|
+
}
|
|
246
|
+
if (typeof aiMessage.content === "string") {
|
|
247
|
+
const msgToYield = messageTokenUsage
|
|
248
|
+
? {
|
|
249
|
+
sessionUpdate: "agent_message_chunk",
|
|
250
|
+
content: {
|
|
251
|
+
type: "text",
|
|
252
|
+
text: aiMessage.content,
|
|
253
|
+
},
|
|
254
|
+
_meta: {
|
|
255
|
+
tokenUsage: messageTokenUsage,
|
|
256
|
+
},
|
|
257
|
+
}
|
|
258
|
+
: {
|
|
259
|
+
sessionUpdate: "agent_message_chunk",
|
|
260
|
+
content: {
|
|
261
|
+
type: "text",
|
|
262
|
+
text: aiMessage.content,
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
console.error("DEBUG agent: yielding message (string content):", JSON.stringify(msgToYield));
|
|
266
|
+
yield msgToYield;
|
|
217
267
|
}
|
|
218
268
|
else if (Array.isArray(aiMessage.content)) {
|
|
219
269
|
for (const part of aiMessage.content) {
|
|
220
270
|
if (part.type === "text" && typeof part.text === "string") {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
271
|
+
const msgToYield = messageTokenUsage
|
|
272
|
+
? {
|
|
273
|
+
sessionUpdate: "agent_message_chunk",
|
|
274
|
+
content: {
|
|
275
|
+
type: "text",
|
|
276
|
+
text: part.text,
|
|
277
|
+
},
|
|
278
|
+
_meta: {
|
|
279
|
+
tokenUsage: messageTokenUsage,
|
|
280
|
+
},
|
|
281
|
+
}
|
|
282
|
+
: {
|
|
283
|
+
sessionUpdate: "agent_message_chunk",
|
|
284
|
+
content: {
|
|
285
|
+
type: "text",
|
|
286
|
+
text: part.text,
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
console.error("DEBUG agent: yielding message (array content):", JSON.stringify(msgToYield));
|
|
290
|
+
yield msgToYield;
|
|
228
291
|
}
|
|
229
292
|
else if (part.type === "tool_use") {
|
|
230
293
|
// We don't care about tool use chunks -- do nothing
|
|
@@ -1,33 +1,49 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export declare const todoItemSchema: z.ZodObject<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
2
|
+
export declare const todoItemSchema: z.ZodObject<
|
|
3
|
+
{
|
|
4
|
+
content: z.ZodString;
|
|
5
|
+
status: z.ZodEnum<{
|
|
6
|
+
pending: "pending";
|
|
7
|
+
in_progress: "in_progress";
|
|
8
|
+
completed: "completed";
|
|
9
|
+
}>;
|
|
10
|
+
activeForm: z.ZodString;
|
|
11
|
+
},
|
|
12
|
+
z.core.$strip
|
|
13
|
+
>;
|
|
14
|
+
export declare const todoWrite: import("langchain").DynamicStructuredTool<
|
|
15
|
+
z.ZodObject<
|
|
16
|
+
{
|
|
17
|
+
todos: z.ZodArray<
|
|
18
|
+
z.ZodObject<
|
|
19
|
+
{
|
|
20
|
+
content: z.ZodString;
|
|
21
|
+
status: z.ZodEnum<{
|
|
22
|
+
pending: "pending";
|
|
23
|
+
in_progress: "in_progress";
|
|
24
|
+
completed: "completed";
|
|
25
|
+
}>;
|
|
26
|
+
activeForm: z.ZodString;
|
|
27
|
+
},
|
|
28
|
+
z.core.$strip
|
|
29
|
+
>
|
|
30
|
+
>;
|
|
31
|
+
},
|
|
32
|
+
z.core.$strip
|
|
33
|
+
>,
|
|
34
|
+
{
|
|
35
|
+
todos: {
|
|
36
|
+
content: string;
|
|
37
|
+
status: "pending" | "in_progress" | "completed";
|
|
38
|
+
activeForm: string;
|
|
39
|
+
}[];
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
todos: {
|
|
43
|
+
content: string;
|
|
44
|
+
status: "pending" | "in_progress" | "completed";
|
|
45
|
+
activeForm: string;
|
|
46
|
+
}[];
|
|
47
|
+
},
|
|
48
|
+
string
|
|
49
|
+
>;
|
|
@@ -4,9 +4,37 @@ structure of this repository is:
|
|
|
4
4
|
- `agents/`: code for main agent loop and configuration
|
|
5
5
|
- `tools/`: code for function-based tools that are shared by agents
|
|
6
6
|
|
|
7
|
+
## Built-in tools
|
|
8
|
+
The following built-in tools are available:
|
|
9
|
+
- `todo_write`: Task management and planning tool
|
|
10
|
+
- `web_search`: Exa-powered web search (requires EXA_API_KEY)
|
|
11
|
+
- `filesystem`: Read, write, and search files in the project directory
|
|
12
|
+
|
|
13
|
+
To use built-in tools, simply add them to the `tools` array in your agent definition:
|
|
14
|
+
```
|
|
15
|
+
const agent: AgentDefinition = {
|
|
16
|
+
model: "claude-sonnet-4-5-20250929",
|
|
17
|
+
systemPrompt: "You are a helpful assistant.\n",
|
|
18
|
+
tools: ["todo_write", "web_search", "filesystem"],
|
|
19
|
+
};
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The `filesystem` tool can also be configured with a custom working directory:
|
|
23
|
+
```
|
|
24
|
+
const agent: AgentDefinition = {
|
|
25
|
+
model: "claude-sonnet-4-5-20250929",
|
|
26
|
+
systemPrompt: "You are a helpful assistant.\n",
|
|
27
|
+
tools: [
|
|
28
|
+
"todo_write",
|
|
29
|
+
"web_search",
|
|
30
|
+
{ type: "filesystem", working_directory: "./src" }
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
7
35
|
## Writing custom tools
|
|
8
|
-
You may add one of the built-in tools
|
|
9
|
-
you may implement your own. To do this:
|
|
36
|
+
You may add one of the built-in tools listed above, or
|
|
37
|
+
you may implement your own custom tools. To do this:
|
|
10
38
|
1. add a file `tools/<tool-name>.ts` with the following structure:
|
|
11
39
|
```
|
|
12
40
|
import * as z from 'zod';
|