Skip to content
Merged
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"threeify",
"transpiling",
"triggerdef",
"uuidv",
"vinxi"
],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ describe('Status Updates', () => {
const context = {
agentTracker: {
getAgents: vi.fn().mockReturnValue([
{ id: 'agent1', goal: 'Task 1', status: AgentStatus.RUNNING },
{ id: 'agent2', goal: 'Task 2', status: AgentStatus.RUNNING },
{ agentId: 'agent1', goal: 'Task 1', status: AgentStatus.RUNNING },
{ agentId: 'agent2', goal: 'Task 2', status: AgentStatus.RUNNING },
]),
},
shellTracker: {
getShells: vi.fn().mockReturnValue([
{
id: 'shell1',
shellId: 'shell1',
status: ShellStatus.RUNNING,
metadata: { command: 'npm test' },
},
Expand All @@ -81,7 +81,7 @@ describe('Status Updates', () => {
browserTracker: {
getSessionsByStatus: vi.fn().mockReturnValue([
{
id: 'session1',
sessionId: 'session1',
status: SessionStatus.RUNNING,
metadata: { url: 'https://example.com' },
},
Expand Down
58 changes: 14 additions & 44 deletions packages/agent/src/core/toolAgent/statusUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ export function generateStatusUpdate(
: undefined;

// Get active sub-agents
const activeAgents = context.agentTracker ? getActiveAgents(context) : [];
const activeAgents = context.agentTracker
? context.agentTracker.getAgents(AgentStatus.RUNNING)
: [];

// Get active shell processes
const activeShells = context.shellTracker ? getActiveShells(context) : [];
const activeShells = context.shellTracker
? context.shellTracker.getShells(ShellStatus.RUNNING)
: [];

console.log('activeShells', activeShells);

// Get active browser sessions
const activeSessions = context.browserTracker
? getActiveSessions(context)
? context.browserTracker.getSessionsByStatus(SessionStatus.RUNNING)
: [];

console.log('activeSessions', activeSessions);

// Format the status message
const statusContent = [
`--- STATUS UPDATE ---`,
Expand All @@ -43,13 +51,13 @@ export function generateStatusUpdate(
`Cost So Far: ${tokenTracker.getTotalCost()}`,
``,
`Active Sub-Agents: ${activeAgents.length}`,
...activeAgents.map((a) => `- ${a.id}: ${a.description}`),
...activeAgents.map((a) => `- ${a.agentId}: ${a.goal}`),
``,
`Active Shell Processes: ${activeShells.length}`,
...activeShells.map((s) => `- ${s.id}: ${s.description}`),
...activeShells.map((s) => `- ${s.shellId}: ${s.metadata.command}`),
``,
`Active Browser Sessions: ${activeSessions.length}`,
...activeSessions.map((s) => `- ${s.id}: ${s.description}`),
...activeSessions.map((s) => `- ${s.sessionId}: ${s.metadata.url ?? ''}`),
``,
usagePercentage !== undefined &&
(usagePercentage >= 50
Expand All @@ -70,41 +78,3 @@ export function generateStatusUpdate(
function formatNumber(num: number): string {
return num.toLocaleString();
}

/**
* Get active agents from the agent tracker
*/
function getActiveAgents(context: ToolContext) {
const agents = context.agentTracker.getAgents(AgentStatus.RUNNING);
return agents.map((agent) => ({
id: agent.id,
description: agent.goal,
status: agent.status,
}));
}

/**
* Get active shells from the shell tracker
*/
function getActiveShells(context: ToolContext) {
const shells = context.shellTracker.getShells(ShellStatus.RUNNING);
return shells.map((shell) => ({
id: shell.id,
description: shell.metadata.command,
status: shell.status,
}));
}

/**
* Get active browser sessions from the session tracker
*/
function getActiveSessions(context: ToolContext) {
const sessions = context.browserTracker.getSessionsByStatus(
SessionStatus.RUNNING,
);
return sessions.map((session) => ({
id: session.id,
description: session.metadata.url || 'No URL',
status: session.status,
}));
}
10 changes: 2 additions & 8 deletions packages/agent/src/core/toolAgent/toolAgentCore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { zodToJsonSchema } from 'zod-to-json-schema';

import { userMessages } from '../../tools/interaction/userMessage.js';
import { utilityTools } from '../../tools/utility/index.js';
import { generateText } from '../llm/core.js';
import { createProvider } from '../llm/provider.js';
Expand Down Expand Up @@ -76,9 +77,7 @@ export const toolAgent = async (
// Check for messages from parent agent
// This assumes the context has an agentTracker and the current agent's ID
if (context.agentTracker && context.currentAgentId) {
const agentState = context.agentTracker.getAgentState(
context.currentAgentId,
);
const agentState = context.agentTracker.getAgent(context.currentAgentId);

// Process any new parent messages
if (
Expand All @@ -104,11 +103,6 @@ export const toolAgent = async (
// Check for messages from user (for main agent only)
// Import this at the top of the file
try {
// Dynamic import to avoid circular dependencies
const { userMessages } = await import(
'../../tools/interaction/userMessage.js'
);

if (userMessages && userMessages.length > 0) {
// Get all user messages and clear the queue
const pendingUserMessages = [...userMessages];
Expand Down
3 changes: 1 addition & 2 deletions packages/agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ export * from './tools/shell/listShells.js';
export * from './tools/shell/ShellTracker.js';

// Tools - Browser
export * from './tools/session/lib/SessionManager.js';
export * from './tools/session/lib/types.js';
export * from './tools/session/sessionMessage.js';
export * from './tools/session/sessionStart.js';
export * from './tools/session/lib/PageController.js';
export * from './tools/session/lib/BrowserAutomation.js';
export * from './tools/session/listSessions.js';
export * from './tools/session/SessionTracker.js';
export * from './tools/session/lib/browserDetectors.js';

export * from './tools/agent/AgentTracker.js';
// Tools - Interaction
Expand Down
Loading
Loading