Tag outgoing SDK calls with a lighter-agent-kit User-Agent#1
Open
kutay25 wants to merge 1 commit into
Open
Conversation
Brand every HTTP request the kit issues through lighter-python with a `User-Agent: lighter-agent-kit/<version> lighter-python/<sdk>` header so the server can attribute traffic to the agent kit (vs. web/mobile/ arbitrary SDK callers). Implementation lives in scripts/_sdk.py as a single helper applied at each ApiClient/SignerClient construction site. SDK version is read via importlib.metadata so it tracks the actually-installed package, with a fallback to lighter.__version__ and finally 'unknown'.
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Brand every HTTP request the kit issues through
lighter-pythonwith aUser-Agentheader so the server can attribute traffic to the agent kit (vs. web/mobile/arbitrary SDK callers).Header format (RFC 7231 product-tokens):
Filter agent-kit traffic server-side with
^lighter-agent-kit/; the trailing token also lets you slice by SDK version.Implementation:
tag_api_client(api_client)inscripts/_sdk.pythat setsapi_client.user_agent(the existing public setter onlighter.ApiClient).lighter.ApiClient(...)andlighter.SignerClient(...)construction site (5 total:query.py×2,paper.py×2,trade.py×1). ForSignerClientthe helper is applied tosigner.api_clientsince the SDK constructs the inner ApiClient itself.importlib.metadata.version("lighter-sdk")so it tracks the actually-installed package; falls back tolighter.__version__then"unknown".lighter-python. Uses the existing OpenAPI-generateduser_agentproperty setter, which is the only existing source-tag mechanism in the SDK today._sdkstub (sdk_mod.tag_api_client = lambda c: c) since they reconstruct_sdkwithtypes.ModuleType.End-to-end verification. Spun up a local HTTP capture server, pointed
LIGHTER_HOSTat it, and exercised every public-read entrypoint. All outgoing requests carried the new UA:Default boilerplate UA before this change was
OpenAPI-Generator/1.0.0/python(set by the auto-generatedlighter/api_client.py:91).pytest tests/→ 73 passed.Review & Testing Checklist for Human
lighter-agent-kit/<version> lighter-python/<sdk>) is what you want logged/aggregated server-side; locking it in here means existing dashboards/regexes will need to match^lighter-agent-kit/.AGENT_KIT_VERSION = "0.1.0"placement inscripts/_sdk.py— this is now the single source of truth for the kit's version (replaces the literal inscripts/health.py, though this PR leaveshealth.pyalone to keep the diff minimal). If you want to consolidate, follow up with a tiny PR.python3 scripts/query.py market list(or any read) against staging or mainnet and confirm a real request appears in your traffic logs with the expected UA.trade.pywrites (signed orders) should also be sampled to confirm the UA propagates on POST/sendTx*paths — this PR applies the same tag toSignerClient.api_client, so they should, but a single signed test order against testnet would close the loop end-to-end.Notes
lighter/ws_client.py) don't carry any tag and aren't used by agent-kit; out of scope.lighter-agent-kit-trade/...) if you ever want that.X-Sourceheader because UA is the only existing tagging convention in the SDK and presumably what web/mobile already use.Link to Devin session: https://app.devin.ai/sessions/6048677bfdf448c88ba064cc4e9ea0bf
Requested by: @kutay25