4.9 KiB
4.9 KiB
Phase 1 Step 15 — Implementation Notes
Status
Done. Phase 1 complete.
Plan reference
- Plan:
docs/PHASE-1-IMPLEMENTATION-PLAN.md - Section: "Step 15: Delete
Configstruct andGlobalConfig"
Summary
Deleted GlobalConfig type alias and all dead Config methods.
Deleted Config::from_parts and bridge tests. Moved 8 flat
runtime fields from RequestContext into ToolScope and
AgentRuntime. RequestContext is now a clean composition of
well-scoped state structs.
What was changed
Dead code deletion
GlobalConfigtype alias — deletedConfig::from_parts— deleted- All bridge.rs tests — deleted
- Dead
Configmethods — deleted (use_agent, use_session_safely, use_role_safely, update, delete, and associated helpers) - Dead
McpRegistrymethods (search_tools_server, describe, invoke) — deleted - Dead
Functionsmethods — deleted - Unused imports cleaned across all files
Field migrations
From RequestContext to ToolScope:
functions: Functions→tool_scope.functions(was duplicated)tool_call_tracker: Option<ToolCallTracker>→tool_scope.tool_tracker
From RequestContext to AgentRuntime:
supervisor: Option<Arc<RwLock<Supervisor>>>→agent_runtime.supervisorparent_supervisor: Option<Arc<RwLock<Supervisor>>>→agent_runtime.parent_supervisorself_agent_id: Option<String>→agent_runtime.self_agent_idcurrent_depth: usize→agent_runtime.current_depthinbox: Option<Arc<Inbox>>→agent_runtime.inboxroot_escalation_queue: Option<Arc<EscalationQueue>>→agent_runtime.escalation_queue
RequestContext accessors added
Accessor methods on RequestContext provide the same API:
current_depth()→ returnsagent_runtime.current_depthor 0supervisor()→ returnsagent_runtime.supervisoror Noneparent_supervisor()→ returns agent_runtime.parent_supervisor or Noneself_agent_id()→ returns agent_runtime.self_agent_id or Noneinbox()→ returns agent_runtime.inbox or Noneroot_escalation_queue()→ returns agent_runtime.escalation_queue or None
AgentRuntime changes
All fields made Option to support agents without spawning
capability (no supervisor), root agents without inboxes, and
lazy escalation queue creation.
Files modified
src/config/request_context.rs— removed 8 flat fields, added accessors, updated all internal methodssrc/config/tool_scope.rs— removed#![allow(dead_code)]src/config/agent_runtime.rs— made fields Optional, removed#![allow(dead_code)], addedDefaultimplsrc/config/bridge.rs— deletedfrom_parts, tests; updatedto_request_contextto buildAgentRuntimesrc/config/mod.rs— deletedGlobalConfig, dead methods, dead runtime fieldssrc/function/mod.rs—ctx.tool_scope.functions,ctx.tool_scope.tool_trackersrc/function/supervisor.rs— agent_runtime construction, accessor methodssrc/function/user_interaction.rs— accessor methodssrc/function/todo.rs— agent_runtime accesssrc/client/common.rs—ctx.tool_scope.tool_trackersrc/config/macros.rs— agent_runtime constructionsrc/repl/mod.rs— tool_scope/agent_runtime accesssrc/main.rs— agent_runtime for startup pathsrc/mcp/mod.rs— deleted dead methods
RequestContext final structure
pub struct RequestContext {
// Shared immutable state
pub app: Arc<AppState>,
// Per-request identity
pub macro_flag: bool,
pub info_flag: bool,
pub working_mode: WorkingMode,
// Current model
pub model: Model,
// Active scope state
pub role: Option<Role>,
pub session: Option<Session>,
pub rag: Option<Arc<Rag>>,
pub agent: Option<Agent>,
pub agent_variables: Option<AgentVariables>,
pub last_message: Option<LastMessage>,
// Tool runtime (functions + MCP + tracker)
pub tool_scope: ToolScope,
// Agent runtime (supervisor + inbox + escalation + depth)
pub agent_runtime: Option<AgentRuntime>,
}
Verification
cargo check— zero warnings, zero errorscargo test— 59 passed, 0 failedGlobalConfigreferences — zero across entire codebase- Flat runtime fields on RequestContext — zero (all moved)
Phase 1 complete
The monolithic Config god-state struct has been broken apart:
| Struct | Purpose | Lifetime |
|---|---|---|
AppConfig |
Serialized config from YAML | Immutable, shared |
AppState |
Process-wide shared state (vault, MCP factory, RAG cache) | Immutable, shared via Arc |
RequestContext |
Per-request mutable state | Owned per request |
ToolScope |
Active tool declarations + MCP runtime + call tracker | Per scope transition |
AgentRuntime |
Agent-specific wiring (supervisor, inbox, escalation) | Per agent activation |
The codebase is ready for Phase 2: REST API endpoints that create
RequestContext per-request from shared AppState.