# eternalwavee/c-agent architecture

> Architecture diagram of the GitHub repository eternalwavee/c-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eternalwavee/c-agent
- Repository: https://github.com/eternalwavee/c-agent

## Overview

C Agent is a terminal programming assistant: a user enters a natural-language task, the Agent exchanges turns with an LLM, dispatches tool calls, and presents the result in the terminal. The product also includes persistent sessions and project memory, skill loading/installation, web access, subagents, and context reclamation. Source-index references and README statements support several internal links; unsampled tool implementations are represented at their existing directory path, and unverified links are omitted.

Main entry points: [`agent/agent.c`](https://github.com/eternalwavee/c-agent/blob/main/agent/agent.c) (Agent Loop), [`tools/executor.c`](https://github.com/eternalwavee/c-agent/blob/main/tools/executor.c) (Tool Executor), [`main.c`](https://github.com/eternalwavee/c-agent/blob/main/main.c) (REPL Entry), [`core/cmd.c`](https://github.com/eternalwavee/c-agent/blob/main/core/cmd.c) (REPL Commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["REPL and Agent"]
  node_main["REPL Entry<br/>[main.c]"]
  node_commands["REPL Commands<br/>[cmd.c]"]
  node_agent["Agent Loop<br/>[agent.c]"]
  node_config["Runtime Config<br/>[config.c]"]
end

subgraph group_reasoning["Reasoning and Context"]
  node_llm["LLM Client<br/>[llm_client.c]"]
  node_prompt["Prompt Builder<br/>[prompt.c]"]
  node_context["Context Policies"]
  node_messages["Message History<br/>[message.c]"]
  node_http["HTTP Client<br/>[http.c]"]
  node_json["JSON Support<br/>[cJSON.c]"]
end

subgraph group_tools["Tool Capabilities"]
  node_tool_dispatch["Tool Executor<br/>[executor.c]"]
  node_workspace_tools["Workspace Tools"]
  node_memory_tools["Memory Tools<br/>[memory_tool.c]"]
  node_web_tools["Web Tools"]
  node_skill_tools["Skill Tools"]
  node_subagents["Subagents<br/>[subagent.c]"]
end

subgraph group_state["Persistent State"]
  node_memory[("Project Memory<br/>[memory.c]")]
  node_sessions[("Session Store<br/>[session.c]")]
  node_skills[("Skill Catalog<br/>[skills.c]")]
  node_hooks["Tool Hooks<br/>[hooks.c]"]
end

subgraph group_presentation["Terminal Rendering"]
  node_ui["Terminal UI<br/>[ui.c]"]
  node_markdown["Markdown Renderer<br/>[markdown.c]"]
  node_md4c["Markdown Parser<br/>[md4c.c]"]
end

node_user(("User"))

node_user -->|"enters tasks"| node_main
node_main -->|"sends input"| node_agent
node_main -->|"dispatches commands"| node_commands
node_main -->|"persists turns"| node_sessions
node_main -->|"renders interaction"| node_ui
node_commands -->|"runs chat"| node_agent
node_commands -->|"manages sessions"| node_sessions
node_commands -->|"triggers consolidation"| node_memory
node_agent -->|"requests responses"| node_llm
node_agent -->|"builds prompt"| node_prompt
node_agent -->|"reclaims context"| node_context
node_agent -->|"maintains history"| node_messages
node_agent -->|"dispatches calls"| node_tool_dispatch
node_agent -->|"updates status"| node_ui
node_llm -->|"sends API requests"| node_http
node_llm -->|"reads settings"| node_config
node_llm -.->|"parses responses"| node_json
node_context -->|"requests summaries"| node_llm
node_context -->|"rewrites history"| node_messages
node_tool_dispatch -->|"executes tools"| node_workspace_tools
node_tool_dispatch -->|"executes tools"| node_memory_tools
node_tool_dispatch -->|"executes tools"| node_web_tools
node_tool_dispatch -->|"executes tools"| node_skill_tools
node_tool_dispatch -->|"executes tools"| node_subagents
node_tool_dispatch -->|"emits lifecycle events"| node_hooks
node_hooks -->|"records observations"| node_memory
node_memory_tools -->|"reads and updates"| node_memory
node_prompt -->|"loads memory context"| node_memory
node_prompt -->|"lists available skills"| node_skills
node_skill_tools -.->|"loads or installs"| node_skills
node_subagents -->|"creates agents"| node_agent
node_context -.->|"stores offloaded output"| node_sessions
node_markdown -->|"parses Markdown"| node_md4c
node_commands -->|"renders command output"| node_markdown
node_main -->|"initializes settings"| node_config

click node_main "https://github.com/eternalwavee/c-agent/blob/main/main.c"
click node_commands "https://github.com/eternalwavee/c-agent/blob/main/core/cmd.c"
click node_agent "https://github.com/eternalwavee/c-agent/blob/main/agent/agent.c"
click node_llm "https://github.com/eternalwavee/c-agent/blob/main/agent/llm_client.c"
click node_prompt "https://github.com/eternalwavee/c-agent/blob/main/agent/prompt.c"
click node_context "https://github.com/eternalwavee/c-agent/tree/main/context"
click node_messages "https://github.com/eternalwavee/c-agent/blob/main/core/message.c"
click node_tool_dispatch "https://github.com/eternalwavee/c-agent/blob/main/tools/executor.c"
click node_workspace_tools "https://github.com/eternalwavee/c-agent/tree/main/tools"
click node_memory_tools "https://github.com/eternalwavee/c-agent/blob/main/tools/memory_tool.c"
click node_web_tools "https://github.com/eternalwavee/c-agent/tree/main/tools"
click node_skill_tools "https://github.com/eternalwavee/c-agent/tree/main/tools"
click node_subagents "https://github.com/eternalwavee/c-agent/blob/main/tools/subagent.c"
click node_memory "https://github.com/eternalwavee/c-agent/blob/main/core/memory.c"
click node_sessions "https://github.com/eternalwavee/c-agent/blob/main/core/session.c"
click node_skills "https://github.com/eternalwavee/c-agent/blob/main/core/skills.c"
click node_hooks "https://github.com/eternalwavee/c-agent/blob/main/core/hooks.c"
click node_ui "https://github.com/eternalwavee/c-agent/blob/main/ui/ui.c"
click node_markdown "https://github.com/eternalwavee/c-agent/blob/main/ui/markdown.c"
click node_http "https://github.com/eternalwavee/c-agent/blob/main/core/http.c"
click node_json "https://github.com/eternalwavee/c-agent/blob/main/libs/cJSON.c"
click node_md4c "https://github.com/eternalwavee/c-agent/blob/main/libs/md4c.c"
click node_config "https://github.com/eternalwavee/c-agent/blob/main/core/config.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_commands,node_agent,node_config,node_user toneBlue
class node_llm,node_prompt,node_context,node_messages,node_http,node_json toneAmber
class node_tool_dispatch,node_workspace_tools,node_memory_tools,node_web_tools,node_skill_tools,node_subagents toneMint
class node_memory,node_sessions,node_skills,node_hooks toneRose
class node_ui,node_markdown,node_md4c toneIndigo
```

## Components

### REPL and Agent

- [REPL Entry](https://github.com/eternalwavee/c-agent/blob/main/main.c): `main.c`
- [REPL Commands](https://github.com/eternalwavee/c-agent/blob/main/core/cmd.c): `core/cmd.c`
- [Agent Loop](https://github.com/eternalwavee/c-agent/blob/main/agent/agent.c): `agent/agent.c`
- [Runtime Config](https://github.com/eternalwavee/c-agent/blob/main/core/config.c): `core/config.c`

### Reasoning and Context

- [LLM Client](https://github.com/eternalwavee/c-agent/blob/main/agent/llm_client.c): `agent/llm_client.c`
- [Prompt Builder](https://github.com/eternalwavee/c-agent/blob/main/agent/prompt.c): `agent/prompt.c`
- [Context Policies](https://github.com/eternalwavee/c-agent/tree/main/context): `context`
- [Message History](https://github.com/eternalwavee/c-agent/blob/main/core/message.c): `core/message.c`
- [HTTP Client](https://github.com/eternalwavee/c-agent/blob/main/core/http.c): `core/http.c`
- [JSON Support](https://github.com/eternalwavee/c-agent/blob/main/libs/cJSON.c): `libs/cJSON.c`

### Tool Capabilities

- [Tool Executor](https://github.com/eternalwavee/c-agent/blob/main/tools/executor.c): `tools/executor.c`
- [Workspace Tools](https://github.com/eternalwavee/c-agent/tree/main/tools): `tools`
- [Memory Tools](https://github.com/eternalwavee/c-agent/blob/main/tools/memory_tool.c): `tools/memory_tool.c`
- [Web Tools](https://github.com/eternalwavee/c-agent/tree/main/tools): `tools`
- [Skill Tools](https://github.com/eternalwavee/c-agent/tree/main/tools): `tools`
- [Subagents](https://github.com/eternalwavee/c-agent/blob/main/tools/subagent.c): `tools/subagent.c`

### Persistent State

- [Project Memory](https://github.com/eternalwavee/c-agent/blob/main/core/memory.c): `core/memory.c`
- [Session Store](https://github.com/eternalwavee/c-agent/blob/main/core/session.c): `core/session.c`
- [Skill Catalog](https://github.com/eternalwavee/c-agent/blob/main/core/skills.c): `core/skills.c`
- [Tool Hooks](https://github.com/eternalwavee/c-agent/blob/main/core/hooks.c): `core/hooks.c`

### Terminal Rendering

- [Terminal UI](https://github.com/eternalwavee/c-agent/blob/main/ui/ui.c): `ui/ui.c`
- [Markdown Renderer](https://github.com/eternalwavee/c-agent/blob/main/ui/markdown.c): `ui/markdown.c`
- [Markdown Parser](https://github.com/eternalwavee/c-agent/blob/main/libs/md4c.c): `libs/md4c.c`

### Other components

- **User**

## Connections

- User → REPL Entry: enters tasks
- REPL Entry → Agent Loop: sends input (evidence: `main.c`)
- REPL Entry → REPL Commands: dispatches commands (evidence: `main.c`)
- REPL Entry → Session Store: persists turns (evidence: `main.c`)
- REPL Entry → Terminal UI: renders interaction (evidence: `main.c`)
- REPL Commands → Agent Loop: runs chat (evidence: `core/cmd.c`)
- REPL Commands → Session Store: manages sessions (evidence: `core/cmd.c`)
- REPL Commands → Project Memory: triggers consolidation (evidence: `core/cmd.c`)
- Agent Loop → LLM Client: requests responses (evidence: `agent/agent.c`)
- Agent Loop → Prompt Builder: builds prompt (evidence: `agent/agent.c`)
- Agent Loop → Context Policies: reclaims context (evidence: `agent/agent.c`)
- Agent Loop → Message History: maintains history (evidence: `agent/agent.c`)
- Agent Loop → Tool Executor: dispatches calls (evidence: `agent/agent.c`)
- Agent Loop → Terminal UI: updates status (evidence: `agent/agent.c`)
- LLM Client → HTTP Client: sends API requests (evidence: `agent/llm_client.c`)
- LLM Client → Runtime Config: reads settings (evidence: `agent/llm_client.c`)
- LLM Client → JSON Support: parses responses
- Context Policies → LLM Client: requests summaries (evidence: `context/policy_summary.c`)
- Context Policies → Message History: rewrites history (evidence: `context/policy_offload.c`)
- Tool Executor → Workspace Tools: executes tools
- Tool Executor → Memory Tools: executes tools
- Tool Executor → Web Tools: executes tools
- Tool Executor → Skill Tools: executes tools
- Tool Executor → Subagents: executes tools
- Tool Executor → Tool Hooks: emits lifecycle events
- Tool Hooks → Project Memory: records observations
- Memory Tools → Project Memory: reads and updates (evidence: `tools/memory_tool.c`)
- Prompt Builder → Project Memory: loads memory context (evidence: `agent/prompt.c`)
- Prompt Builder → Skill Catalog: lists available skills (evidence: `agent/prompt.c`)
- Skill Tools → Skill Catalog: loads or installs
- Subagents → Agent Loop: creates agents (evidence: `tools/subagent.c`)
- Context Policies → Session Store: stores offloaded output
- Markdown Renderer → Markdown Parser: parses Markdown (evidence: `ui/markdown.c`)
- REPL Commands → Markdown Renderer: renders command output (evidence: `core/cmd.c`)
- REPL Entry → Runtime Config: initializes settings (evidence: `main.c`)
