Skip to main content

Pipeline Restructuring Plan

Status: fully implemented. pipeline.go, pipeline_setup.go, pipeline_llm.go, pipeline_execute.go, and pipeline_finalize.go all exist in pkg/agent/. The verification results at the bottom of this document confirm a passing build and test run. Nothing in this plan is pending.

Goal​

Split agent/pipeline.go (~1400 lines) into multiple logical files, organizing code by responsibility.

Final File Structure​

pkg/agent/
├── pipeline.go # Pipeline struct + NewPipeline (~39 lines)
├── pipeline_setup.go # SetupTurn method (~115 lines)
├── pipeline_llm.go # CallLLM method (~519 lines)
├── pipeline_execute.go # ExecuteTools method (~693 lines)
└── pipeline_finalize.go # Finalize method (~78 lines)

Actual Line Counts​

FileLines
pipeline.go39
pipeline_setup.go115
pipeline_llm.go519
pipeline_execute.go693
pipeline_finalize.go78
Total1444

Responsibility Matrix​

FileMethodResponsibility
pipeline.goPipeline struct, NewPipeline()Pipeline dependency container
pipeline_setup.goSetupTurn()Turn initialization: history assembly, message building, candidate selection
pipeline_llm.goCallLLM()LLM call: PreLLM hooks, fallback, retry, AfterLLM hooks
pipeline_execute.goExecuteTools()Tool execution: BeforeTool/ApproveTool/AfterTool hooks, media sending, steering handling
pipeline_finalize.goFinalize()Turn finalization: session save, compression, status setting

Relationship Between Pipeline and Turn Coordinator​

AgentLoop (agent.go)
│
├── runAgentLoop() ──────────────────┐
│ │
│ ┌───────────────────────────────▼───────────────────────────────┐
│ │ Turn Coordinator (turn_coord.go) │
│ │ │
│ │ runTurn() { │
│ │ exec = pipeline.SetupTurn() │
│ │ loop { │
│ │ ctrl = pipeline.CallLLM() ──► Pipeline (pipeline_*.go) │
│ │ if ctrl == ToolLoop { │
│ │ toolCtrl = pipeline.ExecuteTools() │
│ │ } │
│ │ } │
│ │ return pipeline.Finalize() │
│ │ } │
│ └─────────────────────────────────────────────────────────────┘
│
└── Publish response (agent_outbound.go)

Verification Results​

  • ✅ go build ./pkg/agent/... - Pass
  • ✅ go vet ./pkg/agent/... - No warnings
  • ✅ go test ./pkg/agent/... -skip "TestSeahorse|TestGlobalSkillFileContentChange" - Pass