src — agent

Module: src-agent Cohesion: 0.80 Members: 0

src — agent

The src/agent module is the core intelligence and orchestration layer of CodeBuddy. It encapsulates the logic for interacting with Large Language Models (LLMs), executing tools, managing conversational state, and adapting its behavior based on user input and operational context. This module transforms raw user requests into structured plans, executes them, and provides a rich, interactive experience.

Core Agent Architecture

At the heart of the src/agent module are two key classes: BaseAgent and CodeBuddyAgent.

The relationship between CodeBuddyAgent and its key collaborators can be visualized as follows:

graph TD
    subgraph CodeBuddyAgent
        CBA[CodeBuddyAgent]
    end

    subgraph Core Execution
        AE[AgentExecutor]
        TH[ToolHandler]
        PB[PromptBuilder]
        SH[StreamingHandler]
    end

    subgraph State & Infrastructure
        AI[AgentInfrastructure]
        AM[AgentModeManager]
        CM[ContextManagerV2]
        SS[SessionStore]
        CT[CostTracker]
    end

    CBA -- Orchestrates --> AE
    CBA -- Builds Prompts --> PB
    CBA -- Manages Streaming --> SH
    CBA -- Initializes via --> AI
    AI -- Provides Managers --> AM
    AI -- Provides Managers --> CM
    AI -- Provides Managers --> SS
    AI -- Provides Managers --> CT

    AE -- Calls Tools --> TH

Key Components & Functionality

The src/agent module is composed of several specialized files, each handling a distinct aspect of agent behavior:

1. Agent Lifecycle & State Management

CodeBuddyAgent leverages these underlying managers, often exposed through the BaseAgent's facade methods.

2. Execution & Interaction Flow

3. Planning & Advanced Modes

  1. Architect Phase (analyze): An "architect" LLM analyzes the request and generates a detailed ArchitectProposal (summary, steps, affected files, risks, estimated changes).
  2. Editor Phase (implement): An "editor" LLM then executes each ArchitectStep from the proposal, potentially in parallel using buildExecutionWaves for steps without dependencies. This mode is ideal for large, multi-file changes.

4. Context & Memory Management

5. Customization & Extensibility

6. Observability & Debugging

How to Extend and Contribute

Conclusion

The src/agent module is the sophisticated control center of CodeBuddy, bringing together diverse functionalities to create an intelligent, adaptable, and extensible AI assistant. By understanding its modular design and the roles of its various components, developers can effectively contribute to and extend CodeBuddy's capabilities.