Skip to content

Latest commit

 

History

History
95 lines (75 loc) · 3.39 KB

File metadata and controls

95 lines (75 loc) · 3.39 KB

Abstraction Layer Implementation Summary

Last updated: 2026-06-02

Overview

This document summarizes the implementation of a missing abstraction layer between the CLI and core components in the TeaAgent project.

Problem

The CLI handler (cli/_handlers/_agent.py) was directly instantiating core components like RunStore, GitBranchSandbox, UndoJournal, and calling run_chat_agent directly. This created tight coupling between the CLI and core, making the code harder to test and maintain.

Solution

Created a new abstraction layer in teaagent/cli/execution.py that provides:

  1. CommandExecutor Interface - Abstract base class for executing agent commands
  2. AgentExecutionFactory - Factory class for constructing all required components
  3. ExecutionContext - Dataclass to hold all execution context data
  4. DefaultCommandExecutor - Default implementation of the command executor

Files Changed

New Files

  • teaagent/cli/execution.py - New abstraction layer module (209 lines)
  • tests/test_cli_execution.py - Unit tests for the new abstraction layer (144 lines)

Modified Files

  • teaagent/cli/_handlers/_agent.py - Refactored to use the new abstraction layer
    • Added import of execution module
    • Replaced direct component instantiation with factory methods
    • Replaced direct run_chat_agent call with executor pattern
    • Reduced coupling between CLI and core

Key Changes in _agent.py

Before

store = RunStore(args.root)
audit = store.audit_logger()
undo_journal = UndoJournal(args.root)
git_sandbox = GitBranchSandbox(args.root, run_id='pending')
# ... more direct instantiation
result = run_chat_agent(task, adapter, config, ...)

After

factory = AgentExecutionFactory(args.root)
store = factory.create_run_store()
audit = factory.create_audit_logger(store)
undo_journal = factory.create_undo_journal()
git_sandbox = factory.create_git_sandbox(run_id='pending')
# ... more factory methods
config = factory.create_chat_agent_config(...)
context = factory.create_execution_context(...)
executor = DefaultCommandExecutor()
result = executor.execute(context)

Benefits

  1. Separation of Concerns - CLI handlers now focus on argument parsing and user interaction, not component construction
  2. Testability - Components can be mocked more easily through the factory interface
  3. Maintainability - Component construction logic is centralized in one place
  4. Extensibility - New executor implementations can be added without modifying CLI handlers
  5. Type Safety - ExecutionContext provides a clear contract for what data is needed

Test Results

All relevant tests pass:

  • tests/test_cli_ergonomics_handlers.py - 23 passed
  • tests/test_ergonomics.py - 36 passed
  • tests/test_cli_execution.py - 5 passed (new tests)
  • tests/test_cli_chat.py - 41 passed (1 skipped, 1 deselected - unrelated to changes)

Total: 105 tests passed

Architecture

CLI Handler (_agent.py)
    ↓ uses
AgentExecutionFactory
    ↓ creates
ExecutionContext + Components
    ↓ executes
CommandExecutor (DefaultCommandExecutor)
    ↓ calls
Core (run_chat_agent, etc.)

Future Improvements

  1. Add more executor implementations for different execution strategies
  2. Consider adding a builder pattern for complex configurations
  3. Add integration tests for the full execution flow
  4. Consider extracting telemetry setup into the factory as well