AgentShell API Reference¶
AgentShell is a distributed multi-agent terminal coordination system designed to allow autonomous AI agents to collaboratively execute shell commands on shared computational environments. It leverages Conflict-Free Replicated Data Types (CRDTs) and distributed consensus algorithms to ensure conflict-free execution.
Core Modules¶
.worktrees/issue-67fea13a-06-conflict-detector/mat/core/agent_registry.py¶
Manages the registration, discovery, and state tracking of all active agents within the system.
Key Classes/Functions:
AgentRegistry- Signature:
AgentRegistry() - Description: Singleton class responsible for maintaining a global map of registered agents, their capabilities, and current connection statuses.
- Example Usage:
- Signature:
.worktrees/issue-67fea13a-06-conflict-detector/mat/core/file_lock_manager.py¶
Handles distributed locking mechanisms to prevent simultaneous, conflicting writes to shared resources (files, terminal sessions).
Key Classes/Functions:
FileLockManager- Signature:
FileLockManager(resource_id: str, consensus_client) - Description: Manages the acquisition and release of locks for specific shared resources using an underlying consensus mechanism.
- Example Usage:
- Signature:
Coordination Modules¶
.worktrees/issue-67fea13a-06-conflict-detector/mat/coordination/conflict_detector.py¶
Implements the logic for detecting potential conflicts arising from concurrent operations across different agents.
Key Classes/Functions:
ConflictDetector- Signature:
ConflictDetector(history_log: list) - Description: Analyzes sequences of operations against a shared history log to determine if a new proposed operation would lead to a state conflict.
- Example Usage:
- Signature:
.worktrees/issue-67fea13a-06-conflict-detector/mat/coordination/coordinator.py¶
The central orchestration component that mediates requests between agents, applies conflict resolution strategies, and drives the execution workflow.
Key Classes/Functions:
Coordinator- Signature:
Coordinator(registry: AgentRegistry, detector: ConflictDetector) - Description: Coordinates the execution flow. It receives requests, consults the conflict detector, and manages the state transition across agents.
- Example Usage:
- Signature:
Analysis Modules¶
.worktrees/issue-67fea13a-06-conflict-detector/mat/analysis/command_analyzer.py¶
Parses and semantically analyzes shell commands to determine their potential side effects, resource dependencies, and execution complexity.
Key Classes/Functions:
CommandAnalyzer- Signature:
CommandAnalyzer() - Description: Takes a raw shell string and returns a structured representation detailing expected I/O, required permissions, and potential resource locks.
- Example Usage:
- Signature:
.worktrees/issue-67fea13a-06-conflict-detector/mat/cli.py¶
Provides the command-line interface for interacting with the AgentShell system (e.g., starting the coordinator, submitting manual tasks).
Key Classes/Functions:
AgentShellCLI- Signature:
AgentShellCLI(coordinator_instance) - Description: Handles command-line parsing and routes user input to the appropriate internal system components.
- Example Usage:
- Signature:
Terminal State Management (Advanced)¶
.worktrees/issue-67fea13a-06-conflict-detector/mat/analysis/command_analyzer.py (Conceptual Extension)¶
Note: While the primary focus of this module is command parsing, the TerminalStateManager functionality is conceptually integrated here or within a dedicated state module, utilizing Lamport Timestamps and Vector Clocks.
Key Classes/Functions (Conceptual):
TerminalStateManager- Signature:
TerminalStateManager(initial_state: str) - Description: Maintains the causally-consistent state of the terminal buffer across all agents using Vector Clocks for causality tracking and Operational Transformation (OT) for merging concurrent edits.
- Methods:
apply_operation(op: dict, vector_clock: dict) -> tuple[str, dict]: Applies an incoming operation, transforms it against local changes if necessary, and returns the new state and updated vector clock.generate_timestamp(agent_id: str) -> dict: Generates a Lamport timestamp structure for a new event.
- Example Usage:
- Signature: