Commit f34f5ee
feat: Agent SDK with documentation (#3)
* feat: add Agent SDK - Ruby port of Claude Agent SDK
Implements a complete Ruby port of the Claude Agent SDK with:
- CLI subprocess management for spawning claude processes
- Streaming support via Enumerator with Oj for fast JSON parsing
- Multi-turn conversations via Client class with session tracking
- Custom tool definitions with input validation and JSON Schema
- MCP server configuration (stdio, sse, http, sdk transports)
- Hook system for intercepting tool executions (pre/post hooks)
- Permission modes (default, accept_edits, bypass, plan)
- Agent-native introspection for self-describing capabilities
- Fluent builder pattern for configuration (with_* methods)
- Session management with persistence support
- Comprehensive test suite (193 specs)
API matches Python/TypeScript Claude Agent SDKs:
- RubyLLM::AgentSDK.query(prompt, **options) { |msg| ... }
- RubyLLM::AgentSDK.stream(prompt, **options).each { |msg| ... }
- RubyLLM::AgentSDK.client(**options)
- RubyLLM::AgentSDK.tool(name:, description:, input_schema:) { ... }
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: address code review findings for Agent SDK
- Move OJ_AVAILABLE constant inside Stream class (was polluting global namespace)
- Add missing requires: fileutils, time, json in session.rb
- Replace unsafe eval() example in tool.rb documentation with safe pattern
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* refactor: rebuild Agent SDK as proper RubyLLM extension
BREAKING: Completely rewrote Agent SDK to integrate with RubyLLM
The previous implementation wrapped the Claude CLI binary and
didn't use any of RubyLLM's existing infrastructure. This rewrite:
- Uses RubyLLM::Chat for all LLM interactions (works with any provider)
- Built-in tools extend RubyLLM::Tool (Read, Write, Edit, Bash, Glob, Grep)
- Hooks system for intercepting tool executions
- Permission system for controlling tool access
- Fluent API matching RubyLLM's style
Usage:
agent = RubyLLM.agent
.with_tools(RubyLLM::Agent::Tools::Read, RubyLLM::Agent::Tools::Edit)
.with_permission(:allow_all)
.with_max_turns(5)
agent.run("Fix the bug") { |event| puts event.data }
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add AgentSDK - Ruby wrapper for Claude Code CLI
Implements RubyLLM::AgentSDK module that provides programmatic control
of Claude Code CLI, enabling Ruby applications to spawn autonomous agents.
Components:
- CLI: Subprocess management with Open3, array-based spawning (security)
- Stream: JSON-LD parsing with optional Oj for 5-6x performance
- Message: Dynamic message class with type predicates
- Options: Fluent builder pattern matching RubyLLM style
- Client: Multi-turn conversations with session persistence
- Hooks: Pre/post tool hooks with blocking/modification support
- Permissions: Mode constants with CLI camelCase mapping
- Tool: Custom tool definitions with MCP schema conversion
- MCP: Server configurations (stdio, SDK types)
- Introspection: CLI availability, builtin tools, requirements check
Usage:
# One-off query
RubyLLM::AgentSDK.query("prompt").each { |msg| ... }
# Multi-turn client
client = RubyLLM::AgentSDK.client(permission_mode: :bypass_permissions)
client.query("Hello").each { |msg| ... }
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat(agent_sdk): add missing features for 100% SDK parity
Added via TDD:
- cli_path option for custom Claude CLI location
- delegate permission mode
- Session forking with parent_id tracking
- Advanced hook output fields (additional_context, system_message,
continue, stop_reason)
- Hook Matcher class with configurable timeout
- CLIConnectionError for connection failures
- --fork-session CLI flag support
All 67 AgentSDK tests pass.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat(agent_sdk): achieve 100% TypeScript SDK parity
Complete mirror of official Claude Agent SDK:
Options (30+ new):
- Model: fallback_model, max_thinking_tokens, max_budget_usd
- Security: allow_dangerously_skip_permissions
- Session: continue, resume_session_at
- Streaming: include_partial_messages, output_format (JSON schema)
- Advanced: agents, plugins, betas, sandbox, setting_sources
- Directories: additional_directories
- Callbacks: stderr
Hook Events (12 total):
- Added: post_tool_use_failure, subagent_start, permission_request
- Input types for all events (PreToolUseInput, PostToolUseInput, etc.)
- Result: suppress, async, permission decision support
Message Types:
- Types: assistant, user, result, system, stream_event
- Result subtypes: success, error_max_turns, error_during_execution,
error_max_budget_usd, error_max_structured_output_retries
- System subtypes: init, compact_boundary
- Specialized classes: AssistantMessage, UserMessage, ResultMessage,
SystemMessage, PartialMessage
- Helper structs: PermissionDenial, ModelUsage, Usage
CLI Flags:
- All new options mapped to CLI arguments
- System prompt presets support
- Tools presets support
- JSON config for MCP servers, agents, sandbox
150 tests, 0 failures
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add Agent SDK with documentation and tests
- Add comprehensive Agent SDK documentation (11 pages)
- Overview, quickstart, API reference
- Hooks, MCP, sessions, permissions
- Rails integration guide
- Structured output documentation
- Real-world examples
- Add tests for Tool, MCP::Server, Introspection (50 new tests)
- Total: 251 tests passing, 80.68% coverage
- 95%+ feature parity with TypeScript SDK
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* chore: update docs config for GitHub Pages
- Update URL to kieranklaassen.github.io/ruby_llm
- Update GitHub link to fork
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent d37e610 commit f34f5ee
File tree
55 files changed
+11449
-5
lines changed- docs
- agent_sdk
- lib
- ruby_llm
- agent_sdk
- agent
- tools
- plans
- spec/ruby_llm
- agent_sdk
- support
- agent
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
55 files changed
+11449
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
0 commit comments