agent_c 2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +10 -0
  3. data/.ruby-version +1 -0
  4. data/CLAUDE.md +21 -0
  5. data/README.md +360 -0
  6. data/Rakefile +16 -0
  7. data/TODO.md +105 -0
  8. data/agent_c.gemspec +38 -0
  9. data/docs/batch.md +503 -0
  10. data/docs/chat-methods.md +156 -0
  11. data/docs/cost-reporting.md +86 -0
  12. data/docs/pipeline-tips-and-tricks.md +453 -0
  13. data/docs/session-configuration.md +274 -0
  14. data/docs/testing.md +747 -0
  15. data/docs/tools.md +103 -0
  16. data/docs/versioned-store.md +840 -0
  17. data/lib/agent_c/agent/chat.rb +211 -0
  18. data/lib/agent_c/agent/chat_response.rb +38 -0
  19. data/lib/agent_c/agent/chats/anthropic_bedrock.rb +48 -0
  20. data/lib/agent_c/batch.rb +102 -0
  21. data/lib/agent_c/configs/repo.rb +90 -0
  22. data/lib/agent_c/context.rb +56 -0
  23. data/lib/agent_c/costs/data.rb +39 -0
  24. data/lib/agent_c/costs/report.rb +219 -0
  25. data/lib/agent_c/db/store.rb +162 -0
  26. data/lib/agent_c/errors.rb +19 -0
  27. data/lib/agent_c/pipeline.rb +152 -0
  28. data/lib/agent_c/pipelines/agent.rb +219 -0
  29. data/lib/agent_c/processor.rb +98 -0
  30. data/lib/agent_c/prompts.yml +53 -0
  31. data/lib/agent_c/schema.rb +71 -0
  32. data/lib/agent_c/session.rb +206 -0
  33. data/lib/agent_c/store.rb +72 -0
  34. data/lib/agent_c/test_helpers.rb +173 -0
  35. data/lib/agent_c/tools/dir_glob.rb +46 -0
  36. data/lib/agent_c/tools/edit_file.rb +114 -0
  37. data/lib/agent_c/tools/file_metadata.rb +43 -0
  38. data/lib/agent_c/tools/git_status.rb +30 -0
  39. data/lib/agent_c/tools/grep.rb +119 -0
  40. data/lib/agent_c/tools/paths.rb +36 -0
  41. data/lib/agent_c/tools/read_file.rb +94 -0
  42. data/lib/agent_c/tools/run_rails_test.rb +87 -0
  43. data/lib/agent_c/tools.rb +61 -0
  44. data/lib/agent_c/utils/git.rb +87 -0
  45. data/lib/agent_c/utils/shell.rb +58 -0
  46. data/lib/agent_c/version.rb +5 -0
  47. data/lib/agent_c.rb +32 -0
  48. data/lib/versioned_store/base.rb +314 -0
  49. data/lib/versioned_store/config.rb +26 -0
  50. data/lib/versioned_store/stores/schema.rb +127 -0
  51. data/lib/versioned_store/version.rb +5 -0
  52. data/lib/versioned_store.rb +5 -0
  53. data/template/Gemfile +9 -0
  54. data/template/Gemfile.lock +152 -0
  55. data/template/README.md +61 -0
  56. data/template/Rakefile +50 -0
  57. data/template/bin/rake +27 -0
  58. data/template/lib/autoload.rb +10 -0
  59. data/template/lib/config.rb +59 -0
  60. data/template/lib/pipeline.rb +19 -0
  61. data/template/lib/prompts.yml +57 -0
  62. data/template/lib/store.rb +17 -0
  63. data/template/test/pipeline_test.rb +221 -0
  64. data/template/test/test_helper.rb +18 -0
  65. metadata +194 -0
@@ -0,0 +1,274 @@
1
+ # Session Configuration
2
+
3
+ Note: You probably want to make a `Batch`. See the [main README](../README.md)
4
+
5
+ This describes how to create a Session object if you just want to chat with Claude through AgentC.
6
+
7
+ ## Overview
8
+
9
+ AgentC uses a session-based configuration approach that provides isolated configuration with no global state. Each session maintains its own configuration and RubyLLM context, making it ideal for:
10
+ - Testing (no configuration pollution between tests)
11
+ - Multiple concurrent configurations in the same process
12
+ - Better dependency injection and code organization
13
+
14
+ ## Basic Session Configuration
15
+
16
+ ```ruby
17
+ session = Session.new(
18
+ # all chats with claude are saved to a sqlite db.
19
+ # this is separate than your Store's db because
20
+ # why throw anything away. Can be useful for
21
+ # debugging why Claude did what it did
22
+ agent_db_path: "/path/to/your/claude/db.sqlite",
23
+ logger: Logger.new("/dev/null"), # probably use the same logger for everything...
24
+ i18n_path: "/path/to/your/prompts.yml",
25
+
26
+ # as you debug your pipeline, you'll probably run it
27
+ # many times. We tag all Claude chat records with a
28
+ # project so you can track costs.
29
+ project: "SomeProject",
30
+
31
+ # only available for Bedrock...
32
+ ruby_llm: {
33
+ bedrock_api_key: ENV.fetch("AWS_ACCESS_KEY_ID"),
34
+ bedrock_secret_key: ENV.fetch("AWS_SECRET_ACCESS_KEY"),
35
+ bedrock_session_token: ENV.fetch("AWS_SESSION_TOKEN"),
36
+ bedrock_region: ENV.fetch("AWS_REGION", "us-west-2"),
37
+ default_model: ENV.fetch("LLM_MODEL", "us.anthropic.claude-sonnet-4-5-20250929-v1:0")
38
+ }
39
+ )
40
+
41
+ # Create chats from the session
42
+ chat = session.chat
43
+ response = chat.ask("What is Ruby?")
44
+
45
+ # Or use the prompt method for one-off requests
46
+ result = session.prompt(
47
+ prompt: "What is Ruby?",
48
+ schema: -> { string(:answer) }
49
+ )
50
+ ```
51
+
52
+ ## Configuration Options
53
+
54
+ All session parameters are optional except where noted. If database-related features are needed, `agent_db_path` and `project` become required.
55
+
56
+ ### agent_db_path
57
+
58
+ Path to the SQLite database file where all LLM interactions will be stored.
59
+
60
+ ```ruby
61
+ session = Session.new(
62
+ agent_db_path: 'tmp/db/agent.sqlite3'
63
+ )
64
+ ```
65
+
66
+ The database is automatically created if it doesn't exist. All conversations, token usage, and costs are persisted here. Required if using database features (cost tracking, persistence).
67
+
68
+ ### project (required with agent_db_path)
69
+
70
+ A string identifier for your project. Used to organize and filter cost reports.
71
+
72
+ ```ruby
73
+ session = Session.new(
74
+ agent_db_path: 'tmp/db/agent.sqlite3',
75
+ project: 'my_project'
76
+ )
77
+ ```
78
+
79
+ Required when `agent_db_path` is provided.
80
+
81
+ ### workspace_dir
82
+
83
+ The working directory for file-based tools. Tools like `read_file`, `edit_file`, and `dir_glob` operate relative to this directory.
84
+
85
+ ```ruby
86
+ session = Session.new(
87
+ workspace_dir: Dir.pwd
88
+ )
89
+ ```
90
+
91
+ Defaults to `Dir.pwd` if not specified.
92
+
93
+ ### run_id
94
+
95
+ An optional identifier to group related queries. Useful for tracking multiple pipeline runs or sessions.
96
+
97
+ ```ruby
98
+ session = Session.new(
99
+ run_id: Time.now.to_i
100
+ )
101
+ ```
102
+
103
+ Auto-generated if not provided when `agent_db_path` is configured.
104
+
105
+ ### logger
106
+
107
+ Custom logger for debugging:
108
+
109
+ ```ruby
110
+ session = Session.new(
111
+ logger: Logger.new($stdout)
112
+ )
113
+ ```
114
+
115
+ ### i18n_path
116
+
117
+ Path to custom I18n translations file for prompts:
118
+
119
+ ```ruby
120
+ session = Session.new(
121
+ i18n_path: 'config/locales/prompts.yml'
122
+ )
123
+ ```
124
+
125
+ This is particularly useful when using `agent_step` in Pipeline definitions, where prompts and schemas can be loaded from i18n YAML files.
126
+
127
+ ### max_spend_project
128
+
129
+ Maximum project cost threshold in dollars. Raises `AgentC::Errors::AbortCostExceeded` when exceeded:
130
+
131
+ ```ruby
132
+ session = Session.new(
133
+ agent_db_path: 'tmp/db/agent.sqlite3',
134
+ project: 'my_project',
135
+ max_spend_project: 10.0 # Abort if project costs exceed $10
136
+ )
137
+ ```
138
+
139
+ ### max_spend_run
140
+
141
+ Maximum run cost threshold in dollars. Raises `AgentC::Errors::AbortCostExceeded` when exceeded:
142
+
143
+ ```ruby
144
+ session = Session.new(
145
+ agent_db_path: 'tmp/db/agent.sqlite3',
146
+ project: 'my_project',
147
+ run_id: 'run_123',
148
+ max_spend_run: 5.0 # Abort if this run costs exceed $5
149
+ )
150
+ ```
151
+
152
+ ### ruby_llm
153
+
154
+ RubyLLM configuration hash. Each session has its own isolated RubyLLM context:
155
+
156
+ ```ruby
157
+ session = Session.new(
158
+ ruby_llm: {
159
+ bedrock_api_key: ENV['AWS_ACCESS_KEY_ID'],
160
+ bedrock_secret_key: ENV['AWS_SECRET_ACCESS_KEY'],
161
+ bedrock_region: 'us-west-2',
162
+ default_model: 'us.anthropic.claude-sonnet-4-5-20250929-v1:0'
163
+ }
164
+ )
165
+ ```
166
+
167
+ Available RubyLLM options:
168
+ - `bedrock_api_key` - AWS access key
169
+ - `bedrock_secret_key` - AWS secret key
170
+ - `bedrock_session_token` - Optional AWS session token
171
+ - `bedrock_region` - AWS region (e.g., 'us-west-2')
172
+ - `default_model` - Model ID to use
173
+
174
+ ### extra_tools
175
+
176
+ A hash mapping tool names (symbols) to custom tool classes or instances. This allows you to add custom tools beyond the built-in AgentC tools.
177
+
178
+ ```ruby
179
+ session = Session.new(
180
+ extra_tools: {
181
+ my_tool: MyCustomTool, # Class will be initialized
182
+ another_tool: MyOtherTool.new # Instance used directly
183
+ }
184
+ )
185
+ ```
186
+
187
+ When a tool class is provided, AgentC will instantiate it with `workspace_dir:` and `env:` keyword arguments:
188
+
189
+ ```ruby
190
+ # AgentC will call:
191
+ # MyCustomTool.new(workspace_dir: session.workspace_dir, env: session.env)
192
+ ```
193
+
194
+ When a tool instance is provided, it will be used as-is without initialization.
195
+
196
+ Custom tools must implement the tool interface expected by RubyLLM. See the [Custom Tools documentation](custom-tools.md) for details on implementing custom tools.
197
+
198
+ ## Complete Example
199
+
200
+ ```ruby
201
+ require 'agent_c'
202
+ require 'logger'
203
+
204
+ # Create a fully configured session
205
+ session = Session.new(
206
+ # Database and project
207
+ agent_db_path: 'tmp/db/agent.sqlite3',
208
+ project: 'document_processor',
209
+ run_id: Time.now.to_i,
210
+
211
+ # Working directory and i18n
212
+ workspace_dir: Dir.pwd,
213
+ i18n_path: 'config/locales/agent_prompts.yml',
214
+
215
+ # Logging
216
+ logger: Logger.new($stdout, level: Logger::INFO),
217
+
218
+ # Cost controls
219
+ max_spend_project: 100.0,
220
+ max_spend_run: 10.0,
221
+
222
+ # RubyLLM configuration
223
+ ruby_llm: {
224
+ bedrock_api_key: ENV['AWS_ACCESS_KEY_ID'],
225
+ bedrock_secret_key: ENV['AWS_SECRET_ACCESS_KEY'],
226
+ bedrock_region: 'us-west-2',
227
+ default_model: 'us.anthropic.claude-sonnet-4-5-20250929-v1:0'
228
+ },
229
+
230
+ # Custom tools (optional)
231
+ extra_tools: {
232
+ custom_search: MySearchTool,
233
+ api_client: MyApiClient.new(api_key: ENV['API_KEY'])
234
+ }
235
+ )
236
+
237
+ # Create chats from the session
238
+ chat = session.chat(tools: [:read_file, :edit_file])
239
+ response = chat.ask("What is Ruby?")
240
+
241
+ # Or use the prompt method for one-off requests
242
+ result = session.prompt(
243
+ prompt: "Summarize this file",
244
+ schema: -> { string(:summary) },
245
+ tools: [:read_file]
246
+ )
247
+ ```
248
+
249
+ ## Environment-Specific Configuration
250
+
251
+ ```ruby
252
+ session = Session.new(
253
+ agent_db_path: ENV['RACK_ENV'] == 'production' ?
254
+ '/var/db/agent_production.sqlite3' :
255
+ 'tmp/db/agent_development.sqlite3',
256
+ project: ENV['PROJECT_NAME'] || 'default_project',
257
+ workspace_dir: Dir.pwd,
258
+ logger: Logger.new($stdout, level: ENV['LOG_LEVEL'] || 'INFO'),
259
+ ruby_llm: {
260
+ bedrock_region: ENV['AWS_REGION'] || 'us-west-2',
261
+ default_model: ENV['LLM_MODEL'] || 'us.anthropic.claude-sonnet-4-5-20250929-v1:0'
262
+ }
263
+ )
264
+ ```
265
+
266
+ ## AWS Credentials
267
+
268
+ AgentC uses AWS Bedrock for LLM access. Ensure your AWS credentials are configured via:
269
+
270
+ - Environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`)
271
+ - AWS credentials file (`~/.aws/credentials`)
272
+ - IAM role (when running on EC2/ECS)
273
+
274
+ No additional configuration is needed in AgentC for AWS credentials.