feat(agent): identify Go SDK traffic in user agent - #7
Merged
Conversation
Append the go-agent module path (and version, when the build carries one) to the generated SDK's User-Agent so agent traffic is distinguishable from plain go-sdk traffic. Caller middleware still wins: the token is set before the before-request hooks run, so a hook that rewrites User-Agent overrides it. Adds a wire-level regression test that drives NewOpenRouter through CallModel and asserts the token reaches the transport, covering the constructor wiring the unit tests bypass. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Appends the go-agent module path to the generated SDK's
User-Agentso agent traffic is distinguishable from plaingo-sdktraffic.Behavior
NewOpenRouterviadebug.ReadBuildInfo(), checking the main module then deps. A consumer build yieldsgithub.com/OpenRouterTeam/go-agent/<version>; a(devel)or version-less build yields the bare module path.User-Agentstill wins.*http.Requestdoes not accumulate duplicate tokens.Language-specific identity
.upstreamer/upstreamer.mdgains divergence #7: Go appends the module path, TypeScript the npm package name (@openrouter/agent), Python the PyPI distribution name (openrouter-agent-sdk). The porting automation must not converge this token toward the TypeScript literal.Tests
Four unit tests cover append, idempotence, caller override, and
agentUserAgentTokenFromBuildInfoacross five build-info shapes.Added on top of the original patch:
TestNewOpenRouterSendsAgentUserAgentOnTheWire. The four unit tests constructmiddlewareClientdirectly with a hardcoded token, so none of them exerciseNewOpenRouter's wiring or prove the header survives the full SDK path. The new test drivesNewOpenRouterthroughCallModelagainst a recording transport and asserts the agent token arrives last with the generated SDK token preserved.Mutation-checked for teeth: deleting the
req.Header.SetinDofails both it and the unit test. Note that removingagentToken: agentUserAgentToken()fromNewOpenRouterdoes not fail anything —Do'sif agentToken == ""fallback recomputes it, so the constructor assignment is a per-request optimization rather than a correctness path.Verification