Skip to content

Commit ac61683

Browse files
committed
modularity
1 parent 49c468b commit ac61683

File tree

8 files changed

+13
-14
lines changed

8 files changed

+13
-14
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"mycoder-agent": patch
2+
'mycoder-agent': patch
33
---
44

5-
Re-implemented token caching for Vercel AI SDK usage with Anthropic provider to reduce token consumption during repeated API calls.
5+
Re-implemented token caching for Vercel AI SDK usage with Anthropic provider to reduce token consumption during repeated API calls.

.changeset/refactor-tool-agent.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"mycoder-agent": minor
2+
'mycoder-agent': minor
33
---
44

5-
Refactored toolAgent.ts into modular components for improved maintainability and testability. Split into config.ts, messageUtils.ts, toolExecutor.ts, tokenTracking.ts, and types.ts modules.
5+
Refactored toolAgent.ts into modular components for improved maintainability and testability. Split into config.ts, messageUtils.ts, toolExecutor.ts, tokenTracking.ts, and types.ts modules.

packages/agent/src/core/toolAgent.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { anthropic } from '@ai-sdk/anthropic';
21
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
32
import { z } from 'zod';
43

packages/agent/src/core/toolAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export { toolAgent, ToolAgentResult, Tool, ToolContext };
1414
const deprecationWarning = () => {
1515
console.warn(
1616
'Warning: Importing directly from toolAgent.ts is deprecated. ' +
17-
'Please import from the toolAgent directory instead.'
17+
'Please import from the toolAgent directory instead.',
1818
);
1919
};
2020

packages/agent/src/core/toolAgent/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { execSync } from 'child_process';
2+
23
import { anthropic } from '@ai-sdk/anthropic';
34

45
/**

packages/agent/src/core/toolAgent/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { CoreMessage, ToolSet, generateText, tool as makeTool } from 'ai';
2-
import chalk from 'chalk';
32

43
import { getAnthropicApiKeyError } from '../../utils/errors.js';
54

@@ -10,8 +9,8 @@ import {
109
createToolCallParts,
1110
formatToolCalls,
1211
} from './messageUtils.js';
13-
import { executeTools } from './toolExecutor.js';
1412
import { logTokenUsage } from './tokenTracking.js';
13+
import { executeTools } from './toolExecutor.js';
1514
import { Tool, ToolAgentResult, ToolContext } from './types.js';
1615

1716
/**
@@ -62,7 +61,7 @@ export const toolAgent = async (
6261
parameters: tool.parameters,
6362
});
6463
});
65-
64+
6665
// Apply cache control to messages for token caching
6766
const messagesWithCacheControl = [
6867
createCacheControlMessageFromSystemPrompt(systemPrompt),
@@ -75,7 +74,7 @@ export const toolAgent = async (
7574
messages: messagesWithCacheControl,
7675
tools: toolSet,
7776
};
78-
const { text, toolCalls, ...other } = await generateText(generateTextProps);
77+
const { text, toolCalls } = await generateText(generateTextProps);
7978

8079
const localToolCalls = formatToolCalls(toolCalls);
8180

@@ -145,7 +144,7 @@ export const toolAgent = async (
145144
result: 'Maximum sub-agent iterations reach without successful completion',
146145
interactions,
147146
};
148-
147+
149148
logTokenUsage(tokenTracker);
150149
return result;
151150
};

packages/agent/src/core/toolAgent/messageUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export function createCacheControlMessageFromSystemPrompt(
2121
* This marks the last two messages as ephemeral which allows the conversation up to that
2222
* point to be cached (with a ~5 minute window), reducing token usage when making multiple API calls
2323
*/
24-
export function addCacheControlToMessages(messages: CoreMessage[]): CoreMessage[] {
24+
export function addCacheControlToMessages(
25+
messages: CoreMessage[],
26+
): CoreMessage[] {
2527
if (messages.length <= 1) return messages;
2628

2729
// Create a deep copy of the messages array to avoid mutating the original

packages/agent/src/core/toolAgent/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { CoreMessage } from 'ai';
2-
31
// Re-export all types from the original types.ts file
42
export * from '../types.js';
53

0 commit comments

Comments
 (0)