Skip to content

feat: pass AGENTEX_DEPLOYMENT_ID in registration metadata#305

Open
smoreinis wants to merge 2 commits intomainfrom
stas/register-deployment-id
Open

feat: pass AGENTEX_DEPLOYMENT_ID in registration metadata#305
smoreinis wants to merge 2 commits intomainfrom
stas/register-deployment-id

Conversation

@smoreinis
Copy link
Copy Markdown
Contributor

@smoreinis smoreinis commented Apr 3, 2026

Summary

Reads AGENTEX_DEPLOYMENT_ID env var at startup and includes 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.

What changed

  • Added AGENTEX_DEPLOYMENT_ID to EnvVarKeys enum and EnvironmentVariables model (optional, defaults to None)
  • In registration.py, merges deployment_id into the metadata dict before sending the registration POST

Why

Part of the versioned deployments feature (AGX1-171, AGX1-173). The Agentex backend now supports deployment-aware registration — when deployment_id is present in metadata, only the deployment record is updated (not the agent row), enabling preview deployments and explicit promotion.

SGP will inject AGENTEX_DEPLOYMENT_ID as 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

  • All 598 existing tests pass
  • Manual: set AGENTEX_DEPLOYMENT_ID=test-123, verify it appears in registration POST body
  • E2E: deploy with SGP injecting the env var, verify deployment record created as READY

Greptile Summary

This PR adds AGENTEX_DEPLOYMENT_ID env-var support to the agent registration flow. The SDK reads the value at startup and includes it as deployment_id inside registration_metadata when calling POST /agents/register. When the env var is absent, behavior is identical to the pre-existing flow (metadata is still None rather than {}).

Key changes:

  • environment_variables.py: AGENTEX_DEPLOYMENT_ID added to EnvVarKeys enum and EnvironmentVariables model (optional, None default).
  • registration.py: registration_metadata dict is now built by merging get_build_info() with deployment_id (if set), then sending None instead 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 None guard 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

Filename Overview
src/agentex/lib/environment_variables.py Adds AGENTEX_DEPLOYMENT_ID to EnvVarKeys enum and EnvironmentVariables model as an optional string field (defaults to None); correctly placed under a new "# Deployment" section comment.
src/agentex/lib/utils/registration.py Merges deployment_id into registration_metadata before the POST; correctly falls back to None (not {}) when no metadata is present; behavior is unchanged when neither build-info nor AGENTEX_DEPLOYMENT_ID is set.

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 vars
Loading

Reviews (2): Last reviewed commit: "style: add comment explaining or None co..." | Re-trigger Greptile

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.
@smoreinis smoreinis requested a review from danielmillerp April 3, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant