-
Notifications
You must be signed in to change notification settings - Fork 76
Add initial MCP version with SDK imports #44
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
Changes from 7 commits
2da8b6f
7497272
101249f
baa8523
16bda85
e6e46cf
1fad5e2
cdd9df9
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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ import { WaitTool } from '../../tools/Tools.js'; | |
| import { MODEL_SENTINELS } from '../../core/Constants.js'; | ||
| import { ThinkingTool } from '../../tools/ThinkingTool.js'; | ||
| import type { Tool } from '../../tools/Tools.js'; | ||
| import { registerMCPMetaTools } from '../../mcp/MCPMetaTools.js'; | ||
|
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. Fix ESLint import/order violation for MCP import (must come before tools imports). ESLint flags this new import placement. Move it above Apply within this hunk (remove misplaced import): - import { registerMCPMetaTools } from '../../mcp/MCPMetaTools.js';Place this at the top of the import section (before any import { registerMCPMetaTools } from '../../mcp/MCPMetaTools.js';
import { FetcherTool } from '../../tools/FetcherTool.js';
import { FinalizeWithCritiqueTool } from '../../tools/FinalizeWithCritiqueTool.js';
...Optional: If bundle size is a concern, consider lazy-loading MCP meta-tools (dynamic import) guarded by settings/allowlist in a follow-up, but that would require adjusting call sites to handle async. 🧰 Tools🪛 ESLint[error] 22-22: (import/order) 🤖 Prompt for AI Agents |
||
|
|
||
| /** | ||
| * Configuration for the Direct URL Navigator Agent | ||
|
|
@@ -93,6 +94,8 @@ Remember: Always use navigate_url to actually go to the constructed URLs. Return | |
| * Initialize all configured agents | ||
| */ | ||
| export function initializeConfiguredAgents(): void { | ||
| // Ensure MCP meta-tools are available regardless of mode; selection logic decides if they are surfaced | ||
| registerMCPMetaTools(); | ||
| // Register core tools | ||
| ToolRegistry.registerToolFactory('navigate_url', () => new NavigateURLTool()); | ||
| ToolRegistry.registerToolFactory('navigate_back', () => new NavigateBackTool()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,204 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Copyright 2025 The Chromium Authors. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Use of this source code is governed by a BSD-style license that can be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // found in the LICENSE file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { createToolExecutorNode } from './AgentNodes.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ConfigurableAgentTool } from '../agent_framework/ConfigurableAgentTool.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ChatMessageEntity } from '../ui/ChatView.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { AgentState } from './State.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { ConfigurableAgentResult } from '../agent_framework/ConfigurableAgentTool.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| declare global { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function describe(name: string, fn: () => void): void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function it(name: string, fn: () => void): void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function beforeEach(fn: () => void): void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function afterEach(fn: () => void): void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace assert { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function strictEqual(actual: unknown, expected: unknown): void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function deepEqual(actual: unknown, expected: unknown): void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function isTrue(value: unknown): void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function isFalse(value: unknown): void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function doesNotMatch(actual: string, regexp: RegExp): void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe('AgentNodes ToolExecutorNode', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe('ConfigurableAgentTool result filtering', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('should filter out agentSession data from error results', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create a mock ConfigurableAgentTool that returns error with intermediateSteps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockAgentSession = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sessionId: 'test-session-123', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| agentName: 'test-agent', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status: 'error', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messages: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { id: '1', type: 'tool_call', content: { toolName: 'test_tool' } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { id: '2', type: 'tool_result', content: { result: 'test result' } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This contains sensitive data that should not leak to LLM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nestedSessions: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tools: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| startTime: new Date(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| endTime: new Date(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| terminationReason: 'max_iterations' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const errorResultWithSession: ConfigurableAgentResult & { agentSession: any } = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| success: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| error: 'Agent reached maximum iterations', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| terminationReason: 'max_iterations', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This is the problematic field that contains session data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| intermediateSteps: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { entity: ChatMessageEntity.USER, text: 'test query' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { entity: ChatMessageEntity.AGENT_SESSION, agentSession: mockAgentSession, summary: 'test' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| agentSession: mockAgentSession | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+56
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. 🛠️ Refactor suggestion Replace any with a typed extension; avoid leaking agentSession types into LLM. - const errorResultWithSession: ConfigurableAgentResult & { agentSession: any } = {
+ type AgentResultWithSession = ConfigurableAgentResult & { agentSession: unknown };
+ const errorResultWithSession: AgentResultWithSession = {
@@
- class MockConfigurableAgentTool extends ConfigurableAgentTool {
+ class MockConfigurableAgentTool extends ConfigurableAgentTool {
@@
- async execute(): Promise<ConfigurableAgentResult & { agentSession: any }> {
+ async execute(): Promise<AgentResultWithSession> {
return errorResultWithSession;
}
}📝 Committable suggestion
Suggested change
🧰 Tools🪛 ESLint[error] 45-45: Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create mock ConfigurableAgentTool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class MockConfigurableAgentTool extends ConfigurableAgentTool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| super({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'mock_agent', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Mock agent for testing', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| systemPrompt: 'Test prompt', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tools: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: { type: 'object', properties: {}, required: [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async execute(): Promise<ConfigurableAgentResult & { agentSession: any }> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return errorResultWithSession; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockTool = new MockConfigurableAgentTool(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create initial state with a tool call message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const initialState: AgentState = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messages: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| entity: ChatMessageEntity.MODEL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action: 'tool', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toolName: 'mock_agent', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toolArgs: { query: 'test' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toolCallId: 'test-call-id', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isFinalAnswer: false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| agentType: 'web_task', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| context: {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create modified state with mock tool in registry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const stateWithMockTool = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...initialState, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // We need to mock the tool registry or provide tools directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tools: [mockTool] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create ToolExecutorNode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const toolExecutorNode = createToolExecutorNode(stateWithMockTool); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Execute the node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await toolExecutorNode.invoke(stateWithMockTool); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+99
to
+104
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. 🛠️ Refactor suggestion createToolExecutorNode signature updated — pass provider and model. Current test calls will fail to compile. - const toolExecutorNode = createToolExecutorNode(stateWithMockTool);
+ const toolExecutorNode = createToolExecutorNode(
+ stateWithMockTool,
+ 'test' as unknown as LLMProvider,
+ 'test-model'
+ );
@@
- const toolExecutorNode = createToolExecutorNode(stateWithMockTool);
+ const toolExecutorNode = createToolExecutorNode(
+ stateWithMockTool,
+ 'test' as unknown as LLMProvider,
+ 'test-model'
+ );Also applies to: 189-191 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Verify the result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.isTrue(result.messages.length > initialState.messages.length, 'Should add tool result message'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const toolResultMessage = result.messages[result.messages.length - 1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.strictEqual(toolResultMessage.entity, ChatMessageEntity.TOOL_RESULT); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The critical test: resultText should NOT contain agentSession data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const resultText = (toolResultMessage as any).resultText; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.strictEqual(resultText, 'Error: Agent reached maximum iterations'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Verify that the resultText does not contain session data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.doesNotMatch(resultText, /sessionId/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.doesNotMatch(resultText, /test-session-123/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.doesNotMatch(resultText, /intermediateSteps/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.doesNotMatch(resultText, /agentSession/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.doesNotMatch(resultText, /nestedSessions/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The resultText should be clean and only contain the error message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.strictEqual(resultText.includes('test-session-123'), false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('should filter out agentSession data from success results', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create a success result with intermediateSteps containing session data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockAgentSession = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sessionId: 'success-session-456', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| agentName: 'success-agent', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status: 'completed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messages: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nestedSessions: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tools: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| startTime: new Date(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| endTime: new Date(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| terminationReason: 'final_answer' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const successResultWithSession: ConfigurableAgentResult & { agentSession: any } = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| output: 'Task completed successfully', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| terminationReason: 'final_answer', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This should not leak to LLM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| intermediateSteps: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { entity: ChatMessageEntity.AGENT_SESSION, agentSession: mockAgentSession, summary: 'test' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| agentSession: mockAgentSession | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class MockSuccessAgentTool extends ConfigurableAgentTool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| super({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'mock_success_agent', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Mock success agent for testing', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| systemPrompt: 'Test prompt', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tools: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: { type: 'object', properties: {}, required: [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async execute(): Promise<ConfigurableAgentResult & { agentSession: any }> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return successResultWithSession; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+140
to
+166
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. 🛠️ Refactor suggestion Mirror type cleanup for success-path tool result. - const successResultWithSession: ConfigurableAgentResult & { agentSession: any } = {
+ type AgentResultWithSession = ConfigurableAgentResult & { agentSession: unknown };
+ const successResultWithSession: AgentResultWithSession = {
@@
- async execute(): Promise<ConfigurableAgentResult & { agentSession: any }> {
+ async execute(): Promise<AgentResultWithSession> {
return successResultWithSession;
}🧰 Tools🪛 ESLint[error] 140-140: Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any) [error] 162-162: Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockTool = new MockSuccessAgentTool(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const initialState: AgentState = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messages: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| entity: ChatMessageEntity.MODEL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action: 'tool', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toolName: 'mock_success_agent', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toolArgs: { query: 'test' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toolCallId: 'test-call-id-2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isFinalAnswer: false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| agentType: 'web_task', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| context: {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const stateWithMockTool = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...initialState, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tools: [mockTool] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const toolExecutorNode = createToolExecutorNode(stateWithMockTool); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await toolExecutorNode.invoke(stateWithMockTool); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const toolResultMessage = result.messages[result.messages.length - 1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const resultText = (toolResultMessage as any).resultText; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Should contain only the clean output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.strictEqual(resultText, 'Task completed successfully'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Should NOT contain session data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.doesNotMatch(resultText, /success-session-456/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.doesNotMatch(resultText, /intermediateSteps/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.doesNotMatch(resultText, /agentSession/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.