Skip to content

feat: add runtime models.json config, SDK crate, and extension/session-tree/agent-context primitives#1

Merged
jaikoo merged 1 commit intomainfrom
feat/sdk-and-models-config
Apr 25, 2026
Merged

feat: add runtime models.json config, SDK crate, and extension/session-tree/agent-context primitives#1
jaikoo merged 1 commit intomainfrom
feat/sdk-and-models-config

Conversation

@jaikoo
Copy link
Copy Markdown

@jaikoo jaikoo commented Apr 25, 2026

Summary

Implements five phases of missing primitives for building an autonomous AI coding harness comparable to pi-mono/coding-agent.

Phase 1: Runtime models.json Config

  • Load custom providers from ~/.claw/models.json and .claw/models.json
  • Support custom base URLs, API keys (literal or env var), and model definitions
  • Provider-prefixed lookup (e.g. ollama/llama3.1:8b) and bare ID matching
  • Merged discovery: user-level + project-level providers coexist; same-key project overrides user
  • Custom provider routing in ProviderClient respects the api field (anthropic-messages vs openai-completions)
  • Hooks into metadata_for_model, detect_provider_kind, max_tokens_for_model, model_token_limit

Phase 2: SDK Crate (rust/crates/sdk/)

  • AgentSession wraps ConversationRuntime with event-driven lifecycle
  • EventBus provides multi-subscriber broadcast channels for session events
  • SessionManager handles CRUD for persisted sessions
  • ToolRegistry and SdkToolExecutor for tool registration/execution stubs

Phase 3: Extension System

  • Extension trait with lifecycle hooks (on_turn_start, on_turn_complete, on_error)
  • ExtensionRegistry for managing extensions and collecting tools
  • SimpleExtension for basic tool registration

Phase 4: Session Tree

  • Branching/forking/navigation using single-source-of-truth BTreeMap
  • Children stored as ID references (not duplicated node data)
  • Fork at any node, navigate between branches

Phase 5: Inter-Agent Communication

  • AgentContext (thread-safe KV store via Arc<RwLock>)
  • AgentTask with lifecycle (pending -> completed/failed)
  • TaskRegistry for managing sub-agent tasks

Test Coverage

  • 7 e2e tests for models_file (including merge and override scenarios)
  • 27 SDK unit tests
  • 4 models_file unit tests
  • All 1,072 workspace tests pass

Code Review Findings Fixed

  • P1: AgentSession::new now uses the passed tool_registry instead of creating an empty one
  • P1: Custom provider routing now respects the api field (routes anthropic-messages to AnthropicClient)
  • P1: discover_and_load_models now merges user-level and project-level providers instead of replacing
  • P1: SessionTree stores children as ID references to avoid data duplication desync

…n-tree/agent-context primitives

Implements five phases of missing primitives for autonomous AI coding harness:

Phase 1: Runtime-loaded models.json config (~/.claw/models.json, .claw/models.json)
- Custom providers with base URL, API key (literal or env var), and model definitions
- Provider-prefixed lookup (e.g. ollama/llama3.1:8b) and bare ID matching
- Merged discovery: user-level + project-level providers coexist; same-key project overrides user
- Hooks into metadata_for_model, detect_provider_kind, max_tokens_for_model, model_token_limit
- Custom provider routing in ProviderClient respects api field (anthropic-messages vs openai-completions)

Phase 2: SDK crate with AgentSession, EventBus, SessionManager, ToolRegistry
- AgentSession wraps ConversationRuntime with event-driven lifecycle
- EventBus provides multi-subscriber broadcast channels for session events
- SessionManager handles CRUD for persisted sessions
- ToolRegistry and SdkToolExecutor for tool registration/execution stubs

Phase 3: Extension system with Extension trait, ExtensionRegistry, SimpleExtension

Phase 4: SessionTree with branching/forking/navigation using single-source-of-truth BTreeMap
- Children stored as ID references (not duplicated node data)
- Fork at any node, navigate between branches

Phase 5: AgentContext (thread-safe KV store), AgentTask, TaskRegistry, SessionAgent
- Inter-agent communication via shared AgentContext
- Task lifecycle management with completion/failure tracking

Includes 7 e2e tests for models_file, 27 SDK unit tests, 4 models_file unit tests.
All 1,072 workspace tests pass.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@jaikoo jaikoo merged commit a389cba into main Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants