Skip to content

feat(llc): Claude Code session adapter — claude_code adapter type for agent heartbeat #8258

Closed

Description

@mrveiss

Summary

The LLC agent system supports a pluggable adapter protocol (invoke / status / cancel) with adapters for process, http, and autobot_agent types. A claude_code adapter type is needed to allow agents to run Claude Code CLI sessions as their heartbeat execution vehicle.

Problem

Without a claude_code adapter, AI agents that need to run multi-step coding tasks (file edits, test runs, git operations) via Claude Code sessions cannot be plugged into the LLC heartbeat-driven orchestration loop. Teams must fall back to generic process adapters that lack session continuity and context management.

Acceptance Criteria

Adapter Implementation

  • autobot-backend/llc/adapters/claude_code_adapter.py — ClaudeCodeAdapter implementing the three-method adapter protocol
  • invoke(agent_config, context) → run_id: launches claude CLI subprocess with task context injected as system prompt; returns session ID as run_id
  • status(agent_config, run_id) → AdapterRunStatus: reads exit code / in-progress signal from session state file or subprocess
  • cancel(agent_config, run_id) → bool: sends SIGTERM to subprocess; returns True if stopped
  • Adapter registered in AdapterRegistry under key "claude_code"

Context Injection

  • Fat context mode: RAG-assembled brief injected as --system-prompt argument
  • Thin context mode: task_id + API base URL only
  • --output-format stream-json used to capture structured output
  • Tool use permissions scoped per agent config (allowed_tools list in adapter_config)

Session Continuity

  • Session ID stored in Redis llc:agent:{id}:claude_session for multi-turn continuity
  • --resume {session_id} flag used when prior session ID exists and is < 4h old
  • Session ID cleared on cancel or terminated agent status

Quality

  • adapter_config schema: { model, max_turns, allowed_tools, output_dir, timeout_seconds }
  • Unit tests with mock subprocess for invoke, status, cancel
  • Integration test: full invoke → poll status → cancel flow
  • Adapter errors are converted to AdapterRunStatus.failed (never propagate raw exceptions)

Technical Notes

  • Claude Code CLI path resolved via which claude at startup; raises ConfigurationError if not found
  • Output captured to /tmp/llc_agent_{agent_id}_{run_id}.jsonl for post-run KB indexing
  • JSONL output file path stored in heartbeat run record for the KB indexer to pick up

Phase

Phase 2 (adapter layer)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions