Skip to content

Commit f99efbf

Browse files
authored
fix: call-actor output length (#317)
1 parent 889cb9d commit f99efbf

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

src/const.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ export const ACTOR_MAX_MEMORY_MBYTES = 4_096; // If the Actor requires 8GB of me
99

1010
// Tool output
1111
/**
12-
* Usual tool output limit is 25k tokens, let's use 20k
13-
* just in case where 1 token =~ 4 characters thus 80k chars.
12+
* Usual tool output limit is 25k tokens where 1 token =~ 4 characters
13+
* thus 50k chars so we have some buffer becase there was some issue with Claude code Actor call output token count.
1414
* This is primarily used for Actor tool call output, but we can then
1515
* reuse this in other tools as well.
1616
*/
17-
export const TOOL_MAX_OUTPUT_CHARS = 80000;
17+
export const TOOL_MAX_OUTPUT_CHARS = 50000;
1818

1919
// MCP Server
2020
export const SERVER_NAME = 'apify-mcp-server';

src/utils/actor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function ensureOutputWithinCharLimit(items: DatasetItem[], importantField
7575
* If important fields are defined, use only those fields for that fallback step.
7676
*/
7777
let sourceItems = items;
78-
// Try only the important fields
78+
// Try keeping only the important fields
7979
if (importantFields.length > 0) {
8080
const importantItems = items.map((item) => getValuesByDotKeys(item, importantFields));
8181
const importantItemsString = JSON.stringify(importantItems);

tests/unit/utils.actor.test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'vitest';
22

3-
import { getActorDefinitionStorageFieldNames } from '../../src/utils/actor.js';
3+
import { ensureOutputWithinCharLimit, getActorDefinitionStorageFieldNames } from '../../src/utils/actor.js';
44

55
describe('getActorDefinitionStorageFieldNames', () => {
66
it('should return an array of field names from a single view (display.properties and transformation.fields)', () => {
@@ -98,3 +98,40 @@ describe('getActorDefinitionStorageFieldNames', () => {
9898
expect(result.sort()).toEqual(['bar', 'baz', 'foo']);
9999
});
100100
});
101+
102+
describe('ensureOutputWithinCharLimit', () => {
103+
it('should return all items when limit is high', () => {
104+
const items = [
105+
{ id: 1, name: 'Item 1', value: 'test' },
106+
{ id: 2, name: 'Item 2', value: 'test' },
107+
];
108+
const charLimit = JSON.stringify(items).length;
109+
const result = ensureOutputWithinCharLimit(items, [], charLimit);
110+
expect(result).toEqual(items);
111+
});
112+
113+
it('should use important fields when all items exceed limit', () => {
114+
const items = [
115+
{ id: 1, name: 'Item 1', description: 'Very long description that makes this item exceed the limit', extra: 'unnecessary data' },
116+
{ id: 2, name: 'Item 2', description: 'Another long description', extra: 'more unnecessary data' },
117+
];
118+
const importantFields = ['id', 'name'];
119+
const charLimit = 100; // Very small limit
120+
const result = ensureOutputWithinCharLimit(items, importantFields, charLimit);
121+
expect(result).toEqual([
122+
{ id: 1, name: 'Item 1' },
123+
{ id: 2, name: 'Item 2' },
124+
]);
125+
});
126+
127+
it('should remove all items when limit is extremely small', () => {
128+
const items = [
129+
{ id: 1, name: 'Item 1' },
130+
{ id: 2, name: 'Item 2' },
131+
];
132+
const charLimit = 10; // Extremely small limit - even empty array JSON "[]" is 2 chars
133+
const result = ensureOutputWithinCharLimit(items, [], charLimit);
134+
expect(result).toEqual([]);
135+
expect(JSON.stringify(result).length).toBeLessThanOrEqual(charLimit);
136+
});
137+
});

0 commit comments

Comments
 (0)