Skip to content

Commit 091fa99

Browse files
committed
docs: fix doc-audit findings — graph, types, examples, defaults
Fixes all issues found by the doc-audit skill: - Check 2: Create missing CLAUDE.md for neuron-tool, neuron-tool-macros, neuron-context. Add undocumented types to neuron-types (12 types), neuron-mcp (9 types), neuron-runtime (2 types), neuron-loop (1 type). - Check 3: Fix broken sub_agents.rs reference in neuron/README.md, add all 25 examples to Learning Path (was 14, 1 broken). - Check 4: Fix anthropic default flag in installation.md (was "No", should be "Yes" per Cargo.toml default = ["anthropic"]). - Check 7: Fix dependency graph in CLAUDE.md, README.md, llms.txt, and dependency-graph.md to match actual Cargo.toml deps. Key corrections: neuron-mcp depends on neuron-tool (not just types), neuron-context is a peer leaf (not parent of neuron-loop).
1 parent 07994ac commit 091fa99

File tree

13 files changed

+290
-69
lines changed

13 files changed

+290
-69
lines changed

CLAUDE.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,20 @@ When making design decisions, apply these filters in order:
162162
neuron-types (zero deps, the foundation)
163163
^
164164
|-- neuron-provider-* (each implements Provider trait)
165-
|-- neuron-tool (implements Tool trait, registry, middleware)
166-
|-- neuron-mcp (wraps rmcp, bridges to Tool trait)
167-
+-- neuron-context (+ optional Provider for summarization)
165+
|-- neuron-context (compaction strategies, token counting)
166+
+-- neuron-tool (Tool trait, registry, middleware)
168167
^
169-
neuron-loop (composes provider + tool + context)
170-
^
171-
neuron-runtime (sessions, DurableContext, guardrails, sandbox)
172-
^
173-
neuron (umbrella re-export, build LAST)
174-
^
175-
YOUR PROJECTS (sdk, cli, tui, gui)
168+
|-- neuron-mcp (wraps rmcp, bridges to Tool trait)
169+
|-- neuron-loop (provider loop with tool dispatch)
170+
+-- neuron-runtime (sessions, DurableContext, guardrails, sandbox)
171+
^
172+
neuron (umbrella re-export, build LAST)
173+
^
174+
YOUR PROJECTS (sdk, cli, tui, gui)
176175
```
177176

178177
Arrows only point up. No circular dependencies. Each block knows only about
179-
`neuron-types` and the blocks directly below it.
178+
`neuron-types` and the blocks it directly depends on.
180179

181180
**This graph must match actual Cargo.toml dependencies.** When adding or removing
182181
a dependency between crates, update this graph in the same commit.

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
7878
neuron-types (zero deps, the foundation)
7979
^
8080
|-- neuron-provider-* (each implements Provider trait)
81-
|-- neuron-tool (Tool trait, registry, middleware)
82-
|-- neuron-mcp (wraps rmcp, bridges to Tool trait)
83-
+-- neuron-context (+ optional Provider for summarization)
81+
|-- neuron-context (compaction strategies, token counting)
82+
+-- neuron-tool (Tool trait, registry, middleware)
8483
^
85-
neuron-loop (composes provider + tool + context)
86-
^
87-
neuron-runtime (sub-agents, sessions, durability)
88-
^
89-
neuron (umbrella re-export)
84+
|-- neuron-mcp (wraps rmcp, bridges to Tool trait)
85+
|-- neuron-loop (provider loop with tool dispatch)
86+
+-- neuron-runtime (sessions, DurableContext, guardrails, sandbox)
87+
^
88+
neuron (umbrella re-export)
9089
```
9190

9291
Arrows point up. No circular dependencies.

docs/book/src/architecture/dependency-graph.md

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ circular dependencies.
99
```text
1010
neuron-types (zero deps, the foundation)
1111
^
12-
|-- neuron-provider-* (each implements Provider)
13-
|-- neuron-tool (implements Tool, registry, middleware)
14-
|-- neuron-mcp (wraps rmcp, bridges to Tool)
15-
+-- neuron-context (+ optional Provider for summarization)
12+
|-- neuron-provider-* (each implements Provider trait)
13+
|-- neuron-context (compaction strategies, token counting)
14+
+-- neuron-tool (Tool trait, registry, middleware)
1615
^
17-
neuron-loop (composes provider + tool + context)
18-
^
19-
neuron-runtime (sessions, DurableContext, guardrails)
20-
^
21-
neuron (umbrella re-export)
22-
^
23-
YOUR PROJECT (SDK, CLI, TUI, GUI)
16+
|-- neuron-mcp (wraps rmcp, bridges to Tool trait)
17+
|-- neuron-loop (provider loop with tool dispatch)
18+
+-- neuron-runtime (sessions, DurableContext, guardrails, sandbox)
19+
^
20+
neuron (umbrella re-export)
21+
^
22+
YOUR PROJECT (SDK, CLI, TUI, GUI)
2423
```
2524

2625
## Layer by layer
@@ -67,31 +66,31 @@ Implements the tool system:
6766

6867
Depends only on `neuron-types`.
6968

70-
### neuron-mcp (leaf node)
69+
### neuron-mcp
7170

7271
Wraps the `rmcp` crate (the official Rust MCP SDK) and bridges MCP tools into
73-
neuron's `ToolDyn` trait. Depends only on `neuron-types` and `rmcp`.
72+
neuron's `ToolDyn` trait. Depends on `neuron-types`, `neuron-tool`, and `rmcp`.
7473

7574
### neuron-context (leaf node)
7675

7776
Implements `ContextStrategy` for client-side context compaction. Some strategies
7877
(like summarization) optionally use a `Provider` for LLM calls, but the
7978
dependency is on the trait, not on any concrete provider crate.
8079

81-
### neuron-loop (composition layer)
80+
### neuron-loop
8281

83-
The agentic while-loop that composes a provider, tool registry, and context
84-
strategy. This is the ~300-line commodity loop that every agent framework
85-
converges on. It depends on:
82+
The agentic while-loop that composes a provider and tool registry. This is the
83+
~300-line commodity loop that every agent framework converges on. It depends on:
8684

87-
- `neuron-types` (for all trait definitions)
85+
- `neuron-types` (for trait definitions)
86+
- `neuron-tool` (for `ToolRegistry`)
8887

89-
The loop is generic over `<P: Provider>` and accepts a `ToolRegistry` and
90-
optional `ContextStrategy` implementation.
88+
The loop is generic over `<P: Provider, C: ContextStrategy>` and accepts a
89+
`ToolRegistry`. `neuron-context` is a dev-dependency only (for tests).
9190

92-
### neuron-runtime (runtime layer)
91+
### neuron-runtime
9392

94-
Adds cross-cutting runtime concerns on top of the loop:
93+
Adds cross-cutting runtime concerns:
9594

9695
- **Sessions** -- persistent conversation state via `StorageError`-aware backends
9796
- **DurableContext** -- wraps side effects for Temporal/Restate replay
@@ -100,7 +99,8 @@ Adds cross-cutting runtime concerns on top of the loop:
10099
- **PermissionPolicy** -- tool call authorization
101100
- **Sandbox** -- isolated tool execution environments
102101

103-
Depends on `neuron-types` and `neuron-loop`.
102+
Depends on `neuron-types` and `neuron-tool`. `neuron-loop` and `neuron-context`
103+
are dev-dependencies only (for tests).
104104

105105
### neuron (umbrella)
106106

@@ -118,14 +118,15 @@ neuron = { version = "0.2", features = ["anthropic", "openai"] }
118118
or below, never at layer N or above. This is enforced by `Cargo.toml`
119119
dependencies -- circular dependencies are a compile error in Rust.
120120

121-
**Each block knows only about `neuron-types` and the blocks directly below it.**
121+
**Each block knows only about `neuron-types` and the blocks it directly depends on.**
122122
`neuron-tool` has no idea that `neuron-loop` exists. `neuron-provider-anthropic`
123123
has no idea that `neuron-runtime` exists. This means you can use any block
124124
independently.
125125

126-
**No cross-leaf dependencies.** Provider crates do not depend on the tool crate.
127-
The MCP crate does not depend on any provider crate. Leaf nodes are fully
128-
independent of each other.
126+
**Provider crates are fully independent.** Provider crates do not depend on the
127+
tool crate, the MCP crate, or each other. `neuron-mcp`, `neuron-loop`, and
128+
`neuron-runtime` share a dependency on `neuron-tool` but are independent of
129+
each other.
129130

130131
## Practical implications
131132

docs/book/src/getting-started/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cargo add neuron --features anthropic
1919

2020
| Feature | Enables | Default |
2121
|---------|---------|---------|
22-
| `anthropic` | `neuron-provider-anthropic` | No |
22+
| `anthropic` | `neuron-provider-anthropic` | Yes |
2323
| `openai` | `neuron-provider-openai` | No |
2424
| `ollama` | `neuron-provider-ollama` | No |
2525
| `mcp` | `neuron-mcp` (Model Context Protocol) | No |

llms.txt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@ neuron is **serde, not serde_json**. It defines traits, provides foundational im
1212

1313
## Architecture
1414

15-
Dependencies flow upward. Each block depends only on neuron-types and the blocks directly below it.
15+
Dependencies flow upward. Each block depends only on neuron-types and the blocks it directly needs.
1616

1717
```
1818
neuron-types (zero deps, the foundation)
1919
^
2020
|-- neuron-provider-* (each implements Provider trait)
21-
|-- neuron-tool (implements Tool trait, registry, middleware)
22-
|-- neuron-mcp (wraps rmcp, bridges to Tool trait)
23-
+-- neuron-context (+ optional Provider for summarization)
21+
|-- neuron-context (compaction strategies, token counting)
22+
+-- neuron-tool (Tool trait, registry, middleware)
2423
^
25-
neuron-loop (composes provider + tool + context)
26-
^
27-
neuron-runtime (sessions, DurableContext, guardrails, sandbox)
28-
^
29-
neuron (umbrella re-export, build LAST)
24+
|-- neuron-mcp (wraps rmcp, bridges to Tool trait)
25+
|-- neuron-loop (provider loop with tool dispatch)
26+
+-- neuron-runtime (sessions, DurableContext, guardrails, sandbox)
27+
^
28+
neuron (umbrella re-export, build LAST)
3029
```
3130

3231
## Key Traits (all in neuron-types)

neuron-context/CLAUDE.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# neuron-context
2+
3+
Context management strategies for long-running agents -- token counting,
4+
compaction, injection, and persistent context.
5+
6+
## Key types
7+
8+
- `TokenCounter` -- heuristic token estimator using chars-per-token ratio
9+
(default 4.0). Estimates messages, tool definitions, and raw text.
10+
- `InjectionTrigger` -- enum (`EveryNTurns`, `OnTokenThreshold`) controlling
11+
when a `SystemInjector` rule fires.
12+
- `SystemInjector` -- injects system prompt content based on turn count or
13+
token thresholds. Rule-based, checked each turn.
14+
- `ContextSection` -- a named, prioritized text section (label, content,
15+
priority) for structured system prompts.
16+
- `PersistentContext` -- aggregates `ContextSection`s and renders them sorted
17+
by priority into a single string.
18+
- `SlidingWindowStrategy` -- `ContextStrategy` impl that keeps system messages
19+
plus the last N non-system messages. Triggers on token threshold.
20+
- `SummarizationStrategy<P: Provider>` -- `ContextStrategy` impl that
21+
summarizes old messages via an LLM provider, preserving recent messages
22+
verbatim. Generic over `Provider`.
23+
- `ToolResultClearingStrategy` -- `ContextStrategy` impl that replaces old
24+
tool result content with `[tool result cleared]`, keeping the most recent N
25+
intact.
26+
- `CompositeStrategy` -- chains multiple strategies in order, stopping early
27+
when the token count drops below the threshold.
28+
- `BoxedStrategy` -- type-erased wrapper around any `ContextStrategy` for use
29+
in `CompositeStrategy`. Uses `Arc<dyn ErasedStrategy>` internally because
30+
`ContextStrategy` is RPITIT and not dyn-compatible.
31+
32+
## Key design decisions
33+
34+
- **Token counting is heuristic.** `TokenCounter` uses a chars-per-token ratio,
35+
not a real tokenizer. Good enough for compaction thresholds; avoids a
36+
tokenizer dependency.
37+
- **All strategies implement `ContextStrategy`** from `neuron-types`. The loop
38+
calls `should_compact()` / `compact()` / `token_estimate()` uniformly.
39+
- **`BoxedStrategy` exists for type erasure.** `ContextStrategy` uses RPITIT
40+
(`compact` returns `impl Future`), making it not dyn-compatible.
41+
`BoxedStrategy` wraps an internal `ErasedStrategy` trait that boxes the
42+
future, enabling heterogeneous strategy collections in `CompositeStrategy`.
43+
- **`SummarizationStrategy` is the only strategy with a `Provider` dependency.**
44+
It takes a generic `P: Provider` and calls `complete()` to summarize old
45+
messages. All other strategies are pure computation.
46+
- **Fixed cost estimates for images (300) and documents (500).** These are rough
47+
approximations in `TokenCounter` since binary content has no char-based
48+
estimate.
49+
50+
## Dependencies
51+
52+
- `neuron-types` -- `ContextStrategy` trait, `Message`, `ContentBlock`,
53+
`Provider`, `ContextError`
54+
- `serde`, `serde_json` -- serialization
55+
- `tracing` -- instrumentation
56+
57+
Dev-only: `tokio`, `proptest`, `criterion`
58+
59+
## Structure
60+
61+
```
62+
neuron-context/
63+
CLAUDE.md
64+
Cargo.toml
65+
src/
66+
lib.rs # Re-exports all public types
67+
counter.rs # TokenCounter
68+
injector.rs # InjectionTrigger, SystemInjector
69+
persistent.rs # ContextSection, PersistentContext
70+
strategies.rs # SlidingWindowStrategy, SummarizationStrategy,
71+
# ToolResultClearingStrategy, CompositeStrategy,
72+
# BoxedStrategy
73+
benches/
74+
compaction.rs # Criterion benchmarks
75+
```

neuron-loop/CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Agentic while loop for neuron. Composes Provider + Tool + Context.
44

55
## Key types
66
- `AgentLoop<P, C>` — the core loop, generic over Provider and ContextStrategy
7+
- `AgentLoopBuilder<P, C>` — builder pattern for constructing AgentLoop
78
- `LoopConfig` — system prompt, max turns, parallel tool execution
89
- `AgentResult` — final response, messages, usage, turn count
910
- `TurnResult` — per-turn result enum for step-by-step iteration

neuron-mcp/CLAUDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ MCP (Model Context Protocol) integration for neuron.
44

55
## Key types
66
- `McpClient` — connects to MCP servers via stdio or HTTP transport
7+
- `StdioConfig` — configuration for stdio-based MCP connections
8+
- `HttpConfig` — configuration for HTTP-based MCP connections
79
- `McpToolBridge` — bridges MCP tools to `ToolDyn` for use in `ToolRegistry`
810
- `McpServer` — exposes a `ToolRegistry` as an MCP server
911
- `PaginatedList<T>` — paginated response wrapper
12+
- `McpResource`, `McpResourceContents` — MCP resource types
13+
- `McpPrompt`, `McpPromptArgument`, `McpPromptMessage`, `McpPromptContent`, `McpPromptResult` — MCP prompt types
1014

1115
## Key patterns
1216
- Wraps `rmcp` (official Rust MCP SDK), does not reimplement the protocol

neuron-runtime/CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sandboxing.
1010
- `FileSessionStorage` -- one JSON file per session
1111
- `InputGuardrail`, `OutputGuardrail` -- safety checks with Pass/Tripwire/Warn
1212
- `GuardrailResult` -- Pass, Tripwire(reason), Warn(reason)
13+
- `ErasedInputGuardrail`, `ErasedOutputGuardrail` -- type-erased guardrails for dyn dispatch
1314
- `GuardrailHook` -- ObservabilityHook adapter that runs guardrails on PreLlmCall/PostLlmCall
1415
- `LocalDurableContext<P>` -- passthrough DurableContext for local dev
1516
- `Sandbox` trait, `NoOpSandbox` -- tool execution isolation

neuron-tool-macros/CLAUDE.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# neuron-tool-macros
2+
3+
Proc-macro crate that derives `Tool` implementations from annotated async functions.
4+
5+
## Exports
6+
7+
- `#[neuron_tool(name = "...", description = "...")]` — attribute macro applied
8+
to an async function. Generates a zero-sized tool struct, an args struct, and
9+
a `Tool` trait impl.
10+
11+
## What the macro generates
12+
13+
Given a function `calculate`, the macro emits:
14+
15+
- **`CalculateArgs`** — struct with `Deserialize` + `JsonSchema` derives. Fields
16+
come from the function parameters (all except the last `&ToolContext` param).
17+
Doc comments on parameters become doc comments on fields (which `schemars`
18+
picks up for JSON Schema descriptions).
19+
- **`CalculateTool`** — unit struct implementing `neuron_types::Tool`. The impl
20+
provides `NAME`, `Args`/`Output`/`Error` associated types, `definition()`
21+
(builds `ToolDefinition` with schema from `schemars::schema_for!`), and
22+
`call()` (destructures args and runs the original function body).
23+
24+
Naming convention: function name is converted to PascalCase, then suffixed with
25+
`Tool` or `Args`.
26+
27+
## Key design decisions
28+
29+
- **Attribute macro, not derive.** The input is a function, not a struct, so
30+
`#[proc_macro_attribute]` is the correct form.
31+
- **Last parameter must be `&ToolContext`.** The macro strips it from the args
32+
struct and threads it through to `call()`. A `let _ = &ctx;` suppresses
33+
unused-variable warnings when the function uses `_ctx`.
34+
- **Schema via `schemars`** on the generated args struct. The macro does not
35+
hand-build JSON Schema — it relies on `schemars::schema_for!` at the call
36+
site, so the user's crate must depend on `schemars` and `serde_json`.
37+
- **No `ToolDyn` generation.** Type erasure is handled by `ToolRegistry` in
38+
`neuron-tool` when the tool is registered.
39+
- **Return type must be `Result<Output, Error>`.** The macro extracts both type
40+
parameters from the return type at compile time.
41+
- **Compile errors, not panics.** All validation failures return `syn::Error`
42+
for clear diagnostics.
43+
44+
## Dependencies
45+
46+
- `syn` — parsing Rust syntax
47+
- `quote` — generating token streams
48+
- `proc-macro2` — proc-macro utilities
49+
50+
No runtime dependencies. The generated code references `neuron_types`, `serde`,
51+
`schemars`, and `serde_json`, but those are dependencies of the user's crate,
52+
not of this macro crate.
53+
54+
## Structure
55+
56+
```
57+
neuron-tool-macros/
58+
CLAUDE.md
59+
Cargo.toml
60+
src/
61+
lib.rs # Everything: attribute parsing, code generation, helpers
62+
```
63+
64+
Single-file crate. Internal helpers: `AgentToolArgs` (attribute parser),
65+
`to_pascal_case`, `expand_neuron_tool` (main codegen), `extract_result_types`.

0 commit comments

Comments
 (0)