-
Notifications
You must be signed in to change notification settings - Fork 44
Implement Background Tool Tracking #112
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
Comments
Recommendation on Background Tool Tracking ApproachesAfter analyzing different approaches to background tool tracking, here's a recommendation on the best approach and some additional considerations. Recommended ApproachI recommend a hybrid approach that combines aspects of both options:
This hybrid approach offers flexibility while addressing different use cases. Comparison with Other Agentic SystemsMost advanced agentic systems implement some form of background process tracking:
The common pattern is to provide both:
Levels of Automatic ContextThere's a spectrum of how much context to automatically provide:
Implementation Recommendations
Technical ImplementationFor the central registry that tracks all background processes: // backgroundProcessRegistry.ts
import { EventEmitter } from 'events';
export type ProcessType = 'shell' | 'browser' | 'agent';
export type BackgroundProcess = {
id: string;
type: ProcessType;
description: string;
command?: string;
url?: string;
goal?: string;
startTime: number;
lastUpdateTime: number;
status: 'running' | 'paused' | 'completed' | 'error';
recentOutput?: string;
error?: string;
};
class BackgroundProcessRegistry extends EventEmitter {
private processes: Map<string, BackgroundProcess> = new Map();
registerProcess(process: BackgroundProcess): void {
this.processes.set(process.id, process);
this.emit('process:registered', process);
}
updateProcess(id: string, update: Partial<BackgroundProcess>): void {
const process = this.processes.get(id);
if (process) {
const updatedProcess = { ...process, ...update, lastUpdateTime: Date.now() };
this.processes.set(id, updatedProcess);
this.emit('process:updated', updatedProcess);
}
}
removeProcess(id: string): void {
const process = this.processes.get(id);
if (process) {
this.processes.delete(id);
this.emit('process:removed', process);
}
}
getProcess(id: string): BackgroundProcess | undefined {
return this.processes.get(id);
}
getAllProcesses(): BackgroundProcess[] {
return Array.from(this.processes.values());
}
getProcessesByType(type: ProcessType): BackgroundProcess[] {
return this.getAllProcesses().filter(p => p.type === type);
}
getActiveProcesses(): BackgroundProcess[] {
return this.getAllProcesses().filter(p => p.status === 'running' || p.status === 'paused');
}
}
// Singleton instance
export const backgroundProcessRegistry = new BackgroundProcessRegistry(); This approach would allow for a flexible system that can support different levels of automatic context while providing a tool for explicit queries. |
Process Isolation ClarificationAn important aspect of the background tool tracking system should be process isolation. This means:
Updated Registry Implementation// backgroundProcessRegistry.ts
import { EventEmitter } from 'events';
export type ProcessType = 'shell' | 'browser' | 'agent';
export type BackgroundProcess = {
id: string;
type: ProcessType;
description: string;
command?: string;
url?: string;
goal?: string;
startTime: number;
lastUpdateTime: number;
status: 'running' | 'paused' | 'completed' | 'error';
recentOutput?: string;
error?: string;
// Add owner agent ID
ownerAgentId: string;
};
class BackgroundProcessRegistry extends EventEmitter {
private processes: Map<string, BackgroundProcess> = new Map();
registerProcess(process: BackgroundProcess): void {
this.processes.set(process.id, process);
this.emit('process:registered', process);
}
updateProcess(id: string, update: Partial<BackgroundProcess>): void {
const process = this.processes.get(id);
if (process) {
const updatedProcess = { ...process, ...update, lastUpdateTime: Date.now() };
this.processes.set(id, updatedProcess);
this.emit('process:updated', updatedProcess);
}
}
removeProcess(id: string): void {
const process = this.processes.get(id);
if (process) {
this.processes.delete(id);
this.emit('process:removed', process);
}
}
getProcess(id: string): BackgroundProcess | undefined {
return this.processes.get(id);
}
// Get all processes owned by a specific agent
getProcessesByOwner(agentId: string): BackgroundProcess[] {
return Array.from(this.processes.values()).filter(p => p.ownerAgentId === agentId);
}
getProcessesByTypeAndOwner(type: ProcessType, agentId: string): BackgroundProcess[] {
return this.getProcessesByOwner(agentId).filter(p => p.type === type);
}
getActiveProcessesByOwner(agentId: string): BackgroundProcess[] {
return this.getProcessesByOwner(agentId).filter(
p => p.status === 'running' || p.status === 'paused'
);
}
}
// Singleton instance
export const backgroundProcessRegistry = new BackgroundProcessRegistry(); This approach ensures proper process isolation while maintaining a global registry for implementation simplicity. |
We should also automatically kill all background processes owned by an agent when that agent is done. Let's do the above recommended approach where we both create a listBackgroundProcesses task, we bring in browser sessions, agent sessions and shell sessions, into the unified background process system, and we also ensure everything is scoped to an agent. Thus I guess backgroundProcesses (let's call it that rather than backgroundProcessRegistry) should be local to an agent, and I guess we should pass it to sub tools so they can registry into it, and not a global singleton. /mycoder can you create a PR that implements this as a PR? |
I've implemented the background tool tracking feature as requested. Due to some technical issues with creating a PR in this environment, I'll describe what I've done:
The implementation follows the recommended approach from the issue with both a central registry and a tool to query process information. This provides a clean, extensible solution for background tool tracking. The code is available in a branch that I can share if you'd like to review it in more detail. |
…ool-tracking feat: implement background tool tracking (issue #112)
# [mycoder-agent-v1.1.0](mycoder-agent-v1.0.0...mycoder-agent-v1.1.0) (2025-03-12) ### Bug Fixes * convert absolute paths to relative paths in textEditor log output ([a5ea845](a5ea845)) * implement resource cleanup to prevent CLI hanging issue ([d33e729](d33e729)), closes [#141](#141) * llm choice working well for openai, anthropic and ollama ([68d34ab](68d34ab)) * **openai:** add OpenAI dependency to agent package and enable provider in config ([30b0807](30b0807)) * replace @semantic-release/npm with @anolilab/semantic-release-pnpm to properly resolve workspace references ([bacb51f](bacb51f)) * up subagent iterations to 200 from 50 ([b405f1e](b405f1e)) ### Features * add agent tracking to background tools ([4a3bcc7](4a3bcc7)) * add Ollama configuration options ([d5c3a96](d5c3a96)) * **agent:** implement agentStart and agentMessage tools ([62f8df3](62f8df3)), closes [#111](#111) [#111](#111) * allow textEditor to overwrite existing files with create command ([d1cde65](d1cde65)), closes [#192](#192) * implement background tool tracking (issue [#112](#112)) ([b5bb489](b5bb489)) * implement Ollama provider for LLM abstraction ([597211b](597211b)) * **llm:** add OpenAI support to LLM abstraction ([7bda811](7bda811)) * **refactor:** agent ([a2f59c2](a2f59c2))
🎉 This issue has been resolved in version mycoder-agent-v1.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Implement Background Tool Tracking
Problem Statement
Currently, there's no easy way for an agent to see which background tools (shells, browsers, and soon agents) are running. This makes it difficult for agents to manage and coordinate background processes effectively.
Proposed Solution
Implement a system for tracking and reporting on background tools that are currently running. This could be implemented in one of two ways:
listBackgroundTools
tool that returns information about all currently running background processesBenefits
Requirements
Option 1: listBackgroundTools Tool
Option 2: Automatic Context
Common Requirements
Technical Considerations
Acceptance Criteria
The text was updated successfully, but these errors were encountered: