How trpc-group/trpc-agent-go works
Project Type & Purpose
• This is an open-source Go framework (library + CLI/HTTP servers) for building intelligent agent systems.
• It exposes a modular, layered API (packages) that you compose into “Runners” and “Agents,” integrates LLMs, tools, memory, knowledge, and telemetry.
High-Level Architecture & Main Components
A. Core Library
1. Runner
• Orchestrates end-to-end execution: session, telemetry, agent invocation, streaming events
2. Agent
• Interface implementations: LLMAgent, ChainAgent, ParallelAgent, CycleAgent, GraphAgent
3. Planner
• Decides strategy, tool selection, branching (chain/graph/cycle)
4. Executor
• Executes plan steps, invokes Tools or sub-Agents
5. Model Interface
• LLM wrappers (OpenAI, DeepSeek, etc.)
6. Tool Interface
• Tools: function, file ops, DuckDuckGo, MCP, code executor, etc.
B. Services & Stores
7. Session Service
• Manages per-user, per-session context and event streams (in-memory, Redis)
8. Memory Service
• Long-term storage of conversation state (in-memory, Redis)
9. Knowledge Service
• RAG: loaders, chunking, embedders, retrievers, vector stores (in-memory, elasticsearch, pgvector, tcvector)
10. Telemetry
• Tracing & metrics, hooks into runner/agent/model/tool layers, exporters (Langfuse, OpenTelemetry)
C. HTTP Servers & Examples
11. AGUI Server
• SSE endpoints for web UIs, adapter layer
12. A2A Server
• Agent-to-agent tunnel
13. Debug Server
• HTTP + OpenAPI, event replay
Component Relationships & Data Flows
• Runner → Agent
• Runner invokes Agent.Run(…) → returns a stream of events
• Agent → Planner → Model / Knowledge / Memory
• Planner generates a plan (sequence or graph of steps)
• May consult Knowledge Service for RAG retrieval
• May fetch Memory context
• Executor → Tools / Sub-Agents
• Steps that call Tools (e.g., function tool calls local function)
• Or delegate to sub-Agents (ChainAgent, ParallelAgent, GraphAgent)
• Model ↔ External LLM API
• Model interface sends chat prompts, receives streamed responses
• Session / Memory → Storage
• Reads/Writes session state or memory entries to in-memory store or Redis/DB
• Telemetry wraps all calls, emits traces/metrics to exporters
• HTTP Servers expose Runner/Agent as REST/SSE endpoints, adapt requests into Runner.Run calls and stream events over HTTP
Architectural Patterns & Design Principles
• Layered Modular Architecture: clear separation between orchestration (Runner), decision logic (Planner), execution (Executor), and I/O (Model, Tool, Services)
• Plugin/Interface-Driven: each core concept (Agent, Model, Tool, Session, Memory, Knowledge) is defined by an interface, enabling multiple implementations
• Adapter Pattern: Server packages adapt the core Runner/Agent API to HTTP/SSE or other protocols
• Composite Pattern: Multi-agent types (Chain, Parallel, Graph, Cycle) nest or parallelize sub-agents
• Dependency Injection: Users supply tools, memory services, telemetry configurations via functional options