feat(agents): modular SDK runtimes + Anthropic fixes + OpenCode SDK#293
feat(agents): modular SDK runtimes + Anthropic fixes + OpenCode SDK#293rubenmarcus merged 14 commits intomainfrom
Conversation
- Add 'anthropic-sdk' to AgentType union - Add apiKey field to AgentRunOptions and LoopOptions - Implement runAnthropicSdkAgent using @anthropic-ai/sdk with streaming - Update detectAvailableAgents/detectBestAgent to accept apiKeys option - SDK agents are available when API key is provided (no CLI binary needed) - Enables ralph-starter usage in web applications without CLI dependencies Amp-Thread-ID: https://ampcode.com/threads/T-019ce458-6e75-7448-b1cd-1839264ca386 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce458-6e75-7448-b1cd-1839264ca386 Co-authored-by: Amp <amp@ampcode.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Issue Linking ReminderThis PR doesn't appear to have a linked issue. Consider linking to:
Using If this PR doesn't need an issue, you can ignore this message. |
✔️ Bundle Size Analysis
Bundle breakdown |
Amp-Thread-ID: https://ampcode.com/threads/T-019ce458-6e75-7448-b1cd-1839264ca386 Co-authored-by: Amp <amp@ampcode.com>
Greptile SummaryThis PR modularizes the agent runtime by splitting Key changes:
Confidence Score: 2/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[runAgent called] --> B{agent.type}
B -->|claude-code / cursor / codex / opencode / openclaw| C[Build CLI args]
C --> D[runSubprocessAgent\nspawn subprocess]
D --> E[Stream stdout/stderr\nline-by-line via onOutput]
E --> F[Resolve on close / timeout]
B -->|amp| G[runAmpAgent]
G --> G1{amp-sdk importable?}
G1 -->|yes| G2[ampSdk.execute\nasync generator]
G1 -->|no| G3[runAmpCli\nspawn amp --stream-json]
B -->|anthropic-sdk| H[runAnthropicSdkAgent]
H --> H1[client.messages.create\nwith tools]
H1 --> H2{toolCalls.length > 0?}
H2 -->|yes| H3[executeAnthropicTool\nread_file / write_file / list_directory / run_command]
H3 --> H4[Append tool_result to messages]
H4 --> H1
H2 -->|no| H5[Return output]
B -->|opencode-sdk| I[runOpencodeSdkAgent]
I --> I1[createOpencode\nstart local server]
I1 --> I2[client.session.create]
I2 --> I3[client.event.subscribe\nSSE stream]
I3 --> I4[client.session.promptAsync\nfire-and-forget]
I4 --> I5[await streamPromise\nmessage.part.updated events]
I5 --> I6{session.idle or\nsession.error}
I6 --> I7[Return output]
subgraph OutputCollector
OC1[append text] --> OC2[Buffer lines]
OC2 --> OC3[onOutput per line]
end
H --> OutputCollector
I --> OutputCollector
|
- Add file tools (read_file, write_file, list_directory, run_command) - Implement multi-turn tool-use loop so agent can actually edit files - Fix timeout: pass as RequestOptions (2nd arg), not in message body - Fix max_tokens: use fixed 16384 instead of deriving from maxTurns - Fix system prompt: accurately describes tool capabilities Amp-Thread-ID: https://ampcode.com/threads/T-019ce458-6e75-7448-b1cd-1839264ca386 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce458-6e75-7448-b1cd-1839264ca386 Co-authored-by: Amp <amp@ampcode.com>
- Prevent path traversal: resolve + realpath guard on all file tools - Gate run_command behind allowShellExecution option (default: false) - Exclude run_command from tool list entirely when shell disabled - Use remaining time budget for per-request timeout instead of full value Amp-Thread-ID: https://ampcode.com/threads/T-019ce458-6e75-7448-b1cd-1839264ca386 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce48e-f36c-74d2-abf4-e980f10d7bdf Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce48e-f36c-74d2-abf4-e980f10d7bdf Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce48e-f36c-74d2-abf4-e980f10d7bdf Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce48e-f36c-74d2-abf4-e980f10d7bdf Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce48e-f36c-74d2-abf4-e980f10d7bdf Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce48e-f36c-74d2-abf4-e980f10d7bdf Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce4df-e4cc-77c7-b880-50cdc69cd3db Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce4df-e4cc-77c7-b880-50cdc69cd3db Co-authored-by: Amp <amp@ampcode.com>
Summary
This PR upgrades agent execution to support SDK-first workflows while keeping existing CLI behavior.
It now includes:
What Changed
opencode-sdkagent support using@opencode-ai/sdk.anthropic-sdkexecution and fixed tool-loop behavior for tool-use responses.src/loop/agents.tsinto focused modules:src/loop/agents/amp-sdk.tssrc/loop/agents/anthropic-sdk.tssrc/loop/agents/opencode-sdk.tssrc/loop/agents/output-collector.tssrc/loop/agents.tsas the central dispatcher/detection layer.anthropic-sdkandopencode-sdkin--agentoptions.Agent Priority
Current preference order:
claude-code > amp > anthropic-sdk > opencode-sdk > cursor > codex > opencode > openclawSafety / Correctness Notes
end_turn.opencodebinary availability (required by SDK server startup).Validation
pnpm buildpnpm testpnpm typecheckAll passing on this branch.