Repository navigation
Conversation
…de handler
The setup agent is now an AI SDK agent. For a logged-in user, setup
calls aiserver.Config("ldcli-setup-agent").Stream with a new OpenCode
handler. The AI SDK resolves the config through the relay, composes the
prompt from it, and calls the handler. The handler sends that prompt to
the OpenCode session and turns the session's events into the SDK's
stream events. The SDK records the run: an opencode.session span, a
chat span per reply with its tokens, an execute_tool span per tool call,
and the tokens, duration, and success events for the config's
Monitoring tab.
The handler implements the AI SDK's handler contract for agent-mode
configs of any provider, so it can move into go-ai-sdk unchanged. The
wizard still gets every OpenCode event. If the SDK cannot resolve the
config before the handler starts, the run uses the built-in
instructions and task.
Closing a run that ended waits up to 5 seconds for the SDK to record it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
atornsii
added this pull request to stack #902
October 20, 2026 15:48
…de-handler # Conflicts: # go.mod # internal/setup/agent/opencode.go
…de-handler # Conflicts: # internal/setup/agent/opencode.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This runs the setup agent through the Go AI SDK. For a logged-in user, setup calls
aiserver.Config("ldcli-setup-agent").Streamwith a new OpenCode handler. The SDK resolves the config, composes the prompt from it, and calls the handler. The handler sends that prompt to the OpenCode session and turns its events into the SDK's stream events.The SDK records the run: an
opencode.sessionspan, achatspan per reply with its tokens, anexecute_toolspan per tool call, and the tokens, duration, and success events for the config's Monitoring tab.Notes
github.com/launchdarkly/go-ai-sdk/opencodeagents. It can move into go-ai-sdk unchanged.Testing
Handler tests cover the chunks, the output, the token usage, the spans, errors, and a stream without an end. An end-to-end test with the real SDK, a fake relay, and a fake OpenCode checks that the config's prompt and model reach OpenCode and that the relay receives the trace export and the tokens, duration, and success events. A real run against a local gonfalon showed up on the config's Monitoring tab.
Diagram
Blue boxes are new files, orange boxes are changed files, dashed boxes are files from an earlier PR, and purple boxes are outside ldcli. A solid arrow goes from the caller to the code that it calls. A dashed arrow shows data that moves without a direct call.
If the AI SDK is ready,
StartusesstartWithSDK. It starts OpenCode and a session, and thendriveWithSDKcallsaiserver.Config(...).Streamwith the facts and the setup context. The AI SDK composes the prompt from the config and calls the handler inopencode_handler.go. The handler sends the prompt through theSessionEventsfunction, which callspromptAsync. A tap gives the handler a copy of each run event, and the handler turns the events into stream events, chat spans, and tool spans. The AI SDK sends the tracking events and spans out through the proxy. The wizard still reads every event fromrun.Events.This PR uses the SDK client from #897 and the session calls from #894. The wizard from #895 does not change.
Stack
This is one of six PRs for the
ldcli setupagent. Review and merge them in order, after #877 (Go 1.26):They replace #876 and #878.
🤖 Generated with Claude Code