-
-
Notifications
You must be signed in to change notification settings - Fork 277
feat(advisor): render /advisor calls as tool rows with token accounting #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,14 @@ type EntryType = | |
| | 'file-history-snapshot' | ||
| | 'queue-operation'; | ||
|
|
||
| type ContentType = 'text' | 'thinking' | 'tool_use' | 'tool_result' | 'image'; | ||
| type ContentType = | ||
| | 'text' | ||
| | 'thinking' | ||
| | 'tool_use' | ||
| | 'tool_result' | ||
| | 'image' | ||
| | 'server_tool_use' | ||
| | 'advisor_tool_result'; | ||
|
|
||
| type StopReason = 'end_turn' | 'tool_use' | 'max_tokens' | 'stop_sequence' | null; | ||
|
|
||
|
|
@@ -66,12 +73,27 @@ export interface ImageContent extends BaseContent { | |
| }; | ||
| } | ||
|
|
||
| export interface ServerToolUseContent extends BaseContent { | ||
| type: 'server_tool_use'; | ||
| id: string; | ||
| name: string; | ||
| input?: Record<string, unknown>; | ||
| } | ||
|
|
||
| export interface AdvisorToolResultContent extends BaseContent { | ||
| type: 'advisor_tool_result'; | ||
| tool_use_id: string; | ||
| content: { type: 'advisor_result'; text: string }; | ||
| } | ||
|
Comment on lines
+76
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider making Downstream code in 🛡️ Suggested type refinement export interface AdvisorToolResultContent extends BaseContent {
type: 'advisor_tool_result';
tool_use_id: string;
- content: { type: 'advisor_result'; text: string };
+ content?: { type: 'advisor_result'; text: string };
}🤖 Prompt for AI Agents |
||
|
|
||
| export type ContentBlock = | ||
| | TextContent | ||
| | ThinkingContent | ||
| | ToolUseContent | ||
| | ToolResultContent | ||
| | ImageContent; | ||
| | ImageContent | ||
| | ServerToolUseContent | ||
| | AdvisorToolResultContent; | ||
|
|
||
| // ============================================================================= | ||
| // Usage Metadata | ||
|
|
@@ -178,6 +200,7 @@ export interface AssistantEntry extends ConversationalEntry { | |
| message: AssistantMessage; | ||
| requestId: string; | ||
| agentId?: string; | ||
| advisorModel?: string; | ||
| } | ||
|
|
||
| export interface SystemEntry extends ConversationalEntry { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { extractSemanticStepsFromAIChunk } from '../../../../src/main/services/analysis/SemanticStepExtractor'; | ||
| import type { AIChunk } from '../../../../src/main/types/chunks'; | ||
| import type { ParsedMessage } from '../../../../src/main/types/messages'; | ||
| import { | ||
| ADVISOR_CALL_ID, | ||
| ADVISOR_MODEL, | ||
| ADVISOR_TEXT, | ||
| advisorCallMessage, | ||
| advisorResultMessage, | ||
| } from '../../../mocks/advisorBlocks.fixture'; | ||
|
|
||
| function makeChunk(responses: ParsedMessage[]): AIChunk { | ||
| return { | ||
| chunkType: 'ai', | ||
| id: 'chunk-1', | ||
| startTime: new Date('2026-06-06T10:00:00Z'), | ||
| responses, | ||
| processes: [], | ||
| sidechainMessages: [], | ||
| toolExecutions: [], | ||
| userMessage: null as unknown as ParsedMessage, | ||
| } as unknown as AIChunk; | ||
| } | ||
|
|
||
| describe('SemanticStepExtractor — advisor blocks', () => { | ||
| it('extracts a tool_call step from server_tool_use(advisor)', () => { | ||
| const chunk = makeChunk([advisorCallMessage]); | ||
| const steps = extractSemanticStepsFromAIChunk(chunk); | ||
|
|
||
| const callStep = steps.find((s) => s.type === 'tool_call' && s.content.toolName === 'advisor'); | ||
| expect(callStep).toBeDefined(); | ||
| expect(callStep!.id).toBe(ADVISOR_CALL_ID); | ||
| expect(callStep!.content.toolInput).toEqual({}); | ||
| expect(callStep!.content.sourceModel).toBe(ADVISOR_MODEL); | ||
| }); | ||
|
|
||
| it('does NOT add tokens to the advisor tool_call step', () => { | ||
| const chunk = makeChunk([advisorCallMessage]); | ||
| const steps = extractSemanticStepsFromAIChunk(chunk); | ||
|
|
||
| const callStep = steps.find((s) => s.type === 'tool_call' && s.content.toolName === 'advisor'); | ||
| expect(callStep).toBeDefined(); | ||
| expect(callStep!.tokens).toBeUndefined(); | ||
| expect(callStep!.content.tokenCount).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('extracts a tool_result step from advisor_tool_result', () => { | ||
| const chunk = makeChunk([advisorResultMessage]); | ||
| const steps = extractSemanticStepsFromAIChunk(chunk); | ||
|
|
||
| const resultStep = steps.find((s) => s.type === 'tool_result' && s.id === ADVISOR_CALL_ID); | ||
| expect(resultStep).toBeDefined(); | ||
| expect(resultStep!.content.toolResultContent).toBe(ADVISOR_TEXT); | ||
| expect(resultStep!.content.isError).toBe(false); | ||
| }); | ||
|
|
||
| it('counts the advisor result tokens from the advice text', () => { | ||
| const chunk = makeChunk([advisorResultMessage]); | ||
| const steps = extractSemanticStepsFromAIChunk(chunk); | ||
|
|
||
| const resultStep = steps.find((s) => s.type === 'tool_result' && s.id === ADVISOR_CALL_ID); | ||
| expect(resultStep).toBeDefined(); | ||
| // 40 = countContentTokens(ADVISOR_TEXT) — literal guards against tautological re-import | ||
| expect(resultStep!.content.tokenCount).toBe(40); | ||
| expect(resultStep!.content.tokenCount).toBeGreaterThan(0); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Platform incompatibility and port discovery issue.
The
standalone:killscript has two major issues:lsof, which is not available on Windows. Windows users cannot use this script.3456, but the standalone server can bind to ports3456through3466if the preferred port is busy (perHttpServer.ts:124-133). Additionally, if a user setsPORT=3457in the environment, the server will start on3457but this script will target3456.Consider:
netstator PowerShell🔍 Script to verify port binding behavior
🤖 Prompt for AI Agents