feat: pass AGENTEX_DEPLOYMENT_ID in registration metadata#305
Open
feat: pass AGENTEX_DEPLOYMENT_ID in registration metadata#305
Conversation
Read AGENTEX_DEPLOYMENT_ID env var at startup and include it as deployment_id in registration_metadata when calling POST /agents/register. This links the agent pod to its deployment record in the Agentex backend, enabling versioned deployments, preview routing, and promotion. When the env var is not set, behavior is identical to before.
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
Reads
AGENTEX_DEPLOYMENT_IDenv var at startup and includes it asdeployment_idinregistration_metadatawhen callingPOST /agents/register. This links the agent pod to its deployment record in the Agentex backend.What changed
AGENTEX_DEPLOYMENT_IDtoEnvVarKeysenum andEnvironmentVariablesmodel (optional, defaults toNone)registration.py, mergesdeployment_idinto the metadata dict before sending the registration POSTWhy
Part of the versioned deployments feature (AGX1-171, AGX1-173). The Agentex backend now supports deployment-aware registration — when
deployment_idis present in metadata, only the deployment record is updated (not the agent row), enabling preview deployments and explicit promotion.SGP will inject
AGENTEX_DEPLOYMENT_IDas an env var into the pod's Helm values. The SDK reads it and passes it through. When the env var is not set, behavior is identical to before.Depends on
Test plan
AGENTEX_DEPLOYMENT_ID=test-123, verify it appears in registration POST bodyGreptile Summary
This PR adds
AGENTEX_DEPLOYMENT_IDenv-var support to the agent registration flow. The SDK reads the value at startup and includes it asdeployment_idinsideregistration_metadatawhen callingPOST /agents/register. When the env var is absent, behavior is identical to the pre-existing flow (metadata is stillNonerather than{}).Key changes:
environment_variables.py:AGENTEX_DEPLOYMENT_IDadded toEnvVarKeysenum andEnvironmentVariablesmodel (optional,Nonedefault).registration.py:registration_metadatadict is now built by mergingget_build_info()withdeployment_id(if set), then sendingNoneinstead of{}when both sources are empty — preserving the original wire format for unaffected deployments.The implementation is minimal, well-scoped, and the logic is straightforward. No issues were found.
Confidence Score: 5/5
Safe to merge — changes are additive, backward-compatible, and correctly handle the absent-env-var case.
No P0 or P1 issues found. The logic correctly preserves the existing behavior when AGENTEX_DEPLOYMENT_ID is not set, and the
or Noneguard ensures an empty dict is never sent over the wire. All 598 existing tests pass per the test plan.No files require special attention.
Important Files Changed
Sequence Diagram
sequenceDiagram participant SGP as SGP (Helm) participant Pod as Agent Pod participant SDK as SDK (register_agent) participant FS as Filesystem (build-info.json) participant API as Agentex Backend<br/>/agents/register SGP->>Pod: Inject AGENTEX_DEPLOYMENT_ID env var Pod->>SDK: startup → register_agent(env_vars) SDK->>FS: get_build_info() FS-->>SDK: dict | None SDK->>SDK: registration_metadata = build_info or {} alt AGENTEX_DEPLOYMENT_ID is set SDK->>SDK: registration_metadata["deployment_id"] = env_vars.AGENTEX_DEPLOYMENT_ID end SDK->>SDK: payload["registration_metadata"] = metadata or None SDK->>API: POST /agents/register (with deployment_id in metadata) API-->>SDK: 200 OK { id, name, agent_api_key } SDK->>Pod: set AGENT_ID, AGENT_NAME, AGENT_API_KEY env varsReviews (2): Last reviewed commit: "style: add comment explaining or None co..." | Re-trigger Greptile