Skip to content

Commit 874a92e

Browse files
committed
Reverted some changes in the framework for minimal difference with main branch
1 parent ca84eba commit 874a92e

File tree

3 files changed

+33
-59
lines changed

3 files changed

+33
-59
lines changed

front_end/panels/ai_chat/agent_framework/AgentRunner.ts

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class AgentRunner {
194194
defaultCreateErrorResult: AgentRunnerHooks['createErrorResult'],
195195
llmToolArgs?: ConfigurableAgentArgs, // Specific args if triggered by LLM tool call
196196
parentSession?: AgentSession // For natural nesting
197-
): Promise<ConfigurableAgentResult> {
197+
): Promise<ConfigurableAgentResult & { agentSession: AgentSession }> {
198198
const targetAgentName = handoffConfig.targetAgentName;
199199
const targetAgentTool = ToolRegistry.getRegisteredTool(targetAgentName);
200200

@@ -287,32 +287,42 @@ export class AgentRunner {
287287
targetRunnerConfig, // Pass the constructed config
288288
targetRunnerHooks, // Pass the constructed hooks
289289
targetAgentTool, // Target agent is now the executing agent
290-
undefined // No tracing context for handoff (would need to be passed through)
290+
parentSession // Pass parent session for natural nesting
291291
);
292292

293-
logger.info('Handoff target agent ${targetAgentTool.name} finished. Result success: ${handoffResult.success}');
293+
// Extract the result and session
294+
const { agentSession: childSession, ...actualResult } = handoffResult;
295+
296+
// Add child session to parent's nested sessions (natural nesting)
297+
if (parentSession) {
298+
parentSession.nestedSessions.push(childSession);
299+
}
300+
301+
logger.info(`Handoff target agent ${targetAgentTool.name} finished. Result success: ${actualResult.success}`);
294302

295303
// Check if the target agent is configured to *include* intermediate steps
296304
if (targetAgentTool instanceof ConfigurableAgentTool && targetAgentTool.config.includeIntermediateStepsOnReturn === true) {
297305
// Combine message history if the target agent requests it
298306
logger.info(`Including intermediateSteps from ${targetAgentTool.name} based on its config.`);
299307
const combinedIntermediateSteps = [
300308
...currentMessages, // History *before* the recursive call
301-
...(handoffResult.intermediateSteps || []) // History *from* the recursive call (should exist if flag is true)
309+
...(actualResult.intermediateSteps || []) // History *from* the recursive call (should exist if flag is true)
302310
];
303311
// Return the result from the target agent, but with combined history
304312
return {
305-
...handoffResult,
313+
...actualResult,
306314
intermediateSteps: combinedIntermediateSteps,
307-
terminationReason: handoffResult.terminationReason || 'handed_off'
315+
terminationReason: actualResult.terminationReason || 'handed_off',
316+
agentSession: childSession
308317
};
309318
}
310319
// Otherwise (default), omit the target's intermediate steps
311320
logger.info(`Omitting intermediateSteps from ${targetAgentTool.name} based on its config (default or flag set to false).`);
312321
// Return result from target, ensuring intermediateSteps are omitted
313322
const finalResult = {
314-
...handoffResult,
315-
terminationReason: handoffResult.terminationReason || 'handed_off'
323+
...actualResult,
324+
terminationReason: actualResult.terminationReason || 'handed_off',
325+
agentSession: childSession
316326
};
317327
// Explicitly delete intermediateSteps if they somehow exist on actualResult (shouldn't due to target config)
318328
delete finalResult.intermediateSteps;
@@ -326,10 +336,9 @@ export class AgentRunner {
326336
config: AgentRunnerConfig,
327337
hooks: AgentRunnerHooks,
328338
executingAgent: ConfigurableAgentTool | null,
329-
tracingContext?: any
330-
): Promise<ConfigurableAgentResult> {
339+
parentSession?: AgentSession // For natural nesting
340+
): Promise<ConfigurableAgentResult & { agentSession: AgentSession }> {
331341
const agentName = executingAgent?.name || 'Unknown';
332-
333342
logger.info('Starting execution loop for agent: ${agentName}');
334343
const { apiKey, modelName, systemPrompt, tools, maxIterations, temperature } = config;
335344
const { prepareInitialMessages, createSuccessResult, createErrorResult } = hooks;
@@ -343,7 +352,7 @@ export class AgentRunner {
343352
agentDisplayName: executingAgent?.config?.ui?.displayName || agentName,
344353
agentDescription: executingAgent?.config?.description,
345354
sessionId: crypto.randomUUID(),
346-
parentSessionId: undefined, // No parent session for top-level agent
355+
parentSessionId: parentSession?.sessionId,
347356
status: 'running',
348357
startTime: new Date(),
349358
messages: [],
@@ -502,11 +511,6 @@ export class AgentRunner {
502511
logger.info(`${agentName} Created AgentRunner LLM generation trace: ${generationId}`);
503512
}
504513

505-
logger.info('${agentName} Calling LLM with ${messages.length} messages');
506-
507-
// Try to get tracing context from getCurrentTracingContext if not passed explicitly
508-
const effectiveTracingContext = tracingContext || getCurrentTracingContext();
509-
510514
const llm = LLMClient.getInstance();
511515
const provider = AIChatPanel.getProviderForModel(modelName);
512516
const llmMessages = AgentRunner.convertToLLMMessages(messages);
@@ -555,25 +559,6 @@ export class AgentRunner {
555559
duration: Date.now() - generationStartTime.getTime()
556560
});
557561
}
558-
559-
// Update generation observation with output
560-
if (generationId && effectiveTracingContext?.traceId) {
561-
const tracingProvider = createTracingProvider();
562-
try {
563-
await tracingProvider.createObservation({
564-
id: generationId,
565-
name: `LLM Generation (AgentRunner): ${agentName}`,
566-
type: 'generation',
567-
endTime: new Date(),
568-
output: {
569-
response: llmResponse.text || 'No text response',
570-
reasoning: llmResponse.reasoning?.summary
571-
}
572-
}, effectiveTracingContext.traceId);
573-
} catch (tracingError) {
574-
logger.warn('Failed to update generation observation:', tracingError);
575-
}
576-
}
577562
} catch (error: any) {
578563
logger.error(`${agentName} LLM call failed:`, error);
579564
const errorMsg = `LLM call failed: ${error.message || String(error)}`;
@@ -1057,7 +1042,7 @@ export class AgentRunner {
10571042
const { agentSession: childSession, ...actualResult } = handoffResult;
10581043

10591044
// Add child session to current session's nested sessions (natural nesting)
1060-
if (this.currentSession && childSession) {
1045+
if (this.currentSession) {
10611046
this.currentSession.nestedSessions.push(childSession);
10621047
}
10631048

front_end/panels/ai_chat/agent_framework/ConfigurableAgentTool.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import type { Tool } from '../tools/Tools.js';
77
import { AIChatPanel } from '../ui/AIChatPanel.js';
88
import { ChatMessageEntity, type ChatMessage } from '../ui/ChatView.js';
99
import { createLogger } from '../core/Logger.js';
10+
import { getCurrentTracingContext } from '../tracing/TracingConfig.js';
1011
import type { AgentSession } from './AgentSessionTypes.js';
11-
import { getCurrentTracingContext, createTracingProvider } from '../tracing/TracingConfig.js';
1212

1313
const logger = createLogger('ConfigurableAgentTool');
1414

@@ -275,11 +275,6 @@ export interface ConfigurableAgentResult {
275275
*/
276276
content: string;
277277
};
278-
279-
/**
280-
* Agent session information
281-
*/
282-
agentSession?: AgentSession;
283278
}
284279

285280
/**
@@ -388,10 +383,11 @@ export class ConfigurableAgentTool implements Tool<ConfigurableAgentArgs, Config
388383
/**
389384
* Execute the agent
390385
*/
391-
async execute(args: ConfigurableAgentArgs): Promise<ConfigurableAgentResult> {
386+
async execute(args: ConfigurableAgentArgs): Promise<ConfigurableAgentResult & { agentSession: AgentSession }> {
392387
logger.info(`Executing ${this.name} via AgentRunner with args:`, args);
393388

394389
// Get current tracing context for debugging
390+
const tracingContext = getCurrentTracingContext();
395391
const agentService = AgentService.getInstance();
396392
const apiKey = agentService.getApiKey();
397393

@@ -447,25 +443,13 @@ export class ConfigurableAgentTool implements Tool<ConfigurableAgentArgs, Config
447443
: (err, steps, reason) => this.createErrorResult(err, steps, reason),
448444
};
449445

450-
// Get tracing context
451-
let tracingContext = getCurrentTracingContext();
452-
453-
// If no tracing context found, create emergency context for specialized agents
454-
if (!tracingContext?.traceId && (this.name === 'web_task_agent' || this.name === 'direct_url_navigator_agent')) {
455-
tracingContext = {
456-
traceId: `emergency-${this.name}-${Date.now()}`,
457-
sessionId: `emergency-session-${Date.now()}`,
458-
parentObservationId: undefined
459-
};
460-
}
461-
446+
// Run the agent
462447
const result = await AgentRunner.run(
463448
internalMessages,
464449
args,
465450
runnerConfig,
466451
runnerHooks,
467-
this, // Pass the current agent instance as executingAgent
468-
tracingContext // Pass tracing context explicitly
452+
this // Pass the current agent instance as executingAgent
469453
);
470454

471455
// Return the direct result from the runner (including agentSession)

front_end/panels/ai_chat/core/AgentNodes.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { createLogger } from './Logger.js';
1414
import type { AgentState } from './State.js';
1515
import type { Runnable } from './Types.js';
1616
import { AgentErrorHandler } from './AgentErrorHandler.js';
17-
import { createTracingProvider, withTracingContext, getCurrentTracingContext } from '../tracing/TracingConfig.js';
17+
import { createTracingProvider, withTracingContext } from '../tracing/TracingConfig.js';
1818
import type { TracingProvider } from '../tracing/TracingProvider.js';
1919

2020
const logger = createLogger('AgentNodes');
@@ -516,6 +516,11 @@ export function createToolExecutorNode(state: AgentState): Runnable<AgentState,
516516
traceId: tracingContext?.traceId,
517517
toolName
518518
});
519+
console.log(`[TRACING DEBUG] Executing tool ${toolName} with tracing context:`, {
520+
hasTracingContext: !!tracingContext,
521+
traceId: tracingContext?.traceId,
522+
toolName
523+
});
519524

520525
console.log(`[TOOL EXECUTION PATH 1] ToolExecutorNode about to execute tool: ${toolName}`);
521526

0 commit comments

Comments
 (0)