Skip to content

feat(cli): add env support in agent_metadata.yaml#315

Merged
volcano-sh-bot merged 1 commit intovolcano-sh:mainfrom
madmecodes:feat/env-support-metadata
May 11, 2026
Merged

feat(cli): add env support in agent_metadata.yaml#315
volcano-sh-bot merged 1 commit intovolcano-sh:mainfrom
madmecodes:feat/env-support-metadata

Conversation

@madmecodes
Copy link
Copy Markdown
Contributor

Summary

Adds first-class env support to agent_metadata.yaml so users can declare extra environment variables that get injected into sandbox pod containers during publish.

Right now the only way to get custom env vars (like LLM_BASE_URL, LLM_API_KEY) into a deployed agent is to manually patch the CRD after kubectl agentcube publish, and that gets overwritten on the next publish. This change lets you put them straight in the metadata file:

agent_name: my-agent
entrypoint: python main.py
port: 8080
env:
  LLM_BASE_URL: https://api.example.com
  LLM_API_KEY: sk-xxx

What changed

  • metadata_service.py -- added env: Optional[Dict[str, str]] field to AgentMetadata model. Defaults to None, excluded from saved YAML when absent.
  • publish_runtime.py -- both _publish_cr_to_k8s (AgentRuntime CR) and _publish_k8s (standard Deployment) now read metadata.env and merge it into the env_vars dict before passing to providers. Programmatic env_vars from options still override metadata values.
  • tests/test_env_support.py -- 10 unit tests covering model validation, YAML round-trip, and env forwarding to both providers.

Fixes #222

Test plan

  • AgentMetadata accepts env dict, defaults to None
  • YAML load/save round-trips env correctly
  • Saving metadata without env omits the field from YAML
  • env from metadata forwarded to AgentCube provider
  • env from metadata forwarded to K8s provider
  • No env passes None to providers (no regression)
  • All 10 tests pass locally

Copilot AI review requested due to automatic review settings May 10, 2026 18:00
@volcano-sh-bot
Copy link
Copy Markdown
Contributor

Welcome @madmecodes! It looks like this is your first PR to volcano-sh/agentcube 🎉

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for user-defined environment variables in agent_metadata.yaml by introducing an env field to the AgentMetadata model. The PublishRuntime logic was updated to merge these variables with CLI options during deployment, and a comprehensive test suite was added to ensure correct parsing and forwarding. Feedback suggests using dictionary unpacking to simplify the environment variable merging logic and reduce code duplication.

Comment on lines +154 to +156
env_vars = dict(metadata.env) if metadata.env else {}
if options.get('env_vars'):
env_vars.update(options['env_vars'])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for merging environment variables can be simplified using dictionary unpacking. This approach is more concise and handles potential None values gracefully while ensuring that CLI options correctly override metadata values.

Suggested change
env_vars = dict(metadata.env) if metadata.env else {}
if options.get('env_vars'):
env_vars.update(options['env_vars'])
env_vars = {**(metadata.env or {}), **(options.get('env_vars') or {})}

Comment on lines +238 to +240
env_vars = dict(metadata.env) if metadata.env else {}
if options.get('env_vars'):
env_vars.update(options['env_vars'])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This merge logic is duplicated from _publish_cr_to_k8s. Using a concise dictionary unpacking approach improves readability and maintainability by reducing the boilerplate needed for merging optional dictionaries.

Suggested change
env_vars = dict(metadata.env) if metadata.env else {}
if options.get('env_vars'):
env_vars.update(options['env_vars'])
env_vars = {**(metadata.env or {}), **(options.get('env_vars') or {})}

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds first-class support for user-defined environment variables in agent_metadata.yaml and wires them through the CLI publish flow so they are injected into sandbox pod containers for both the AgentRuntime CRD (“agentcube” provider) and standard Deployment (“k8s” provider).

Changes:

  • Extend the AgentMetadata model to include an optional env: Dict[str, str] field that is omitted from saved YAML when None.
  • Merge metadata.env with any programmatic env_vars options during publish (options take precedence) and forward the merged env to both deployment providers.
  • Add unit tests covering metadata YAML round-trip and env forwarding behavior.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 6 comments.

File Description
cmd/cli/agentcube/services/metadata_service.py Adds env field to AgentMetadata and relies on existing exclude_none=True YAML saving behavior.
cmd/cli/agentcube/runtime/publish_runtime.py Merges metadata.env into env_vars and forwards to both AgentCube and Kubernetes providers.
cmd/cli/tests/test_env_support.py New tests for env parsing/persistence and publish-time env forwarding.
cmd/cli/tests/init.py No functional changes (file present for test package).

Comment thread cmd/cli/tests/test_env_support.py Outdated
from unittest.mock import MagicMock, patch

import yaml
import pytest

with tempfile.TemporaryDirectory() as tmpdir:
result = runtime.publish(Path(tmpdir), provider="agentcube")

Comment on lines +221 to +223
with tempfile.TemporaryDirectory() as tmpdir:
result = runtime.publish(Path(tmpdir), provider="k8s")

Comment on lines +257 to +259
with tempfile.TemporaryDirectory() as tmpdir:
result = runtime.publish(Path(tmpdir), provider="agentcube")

Comment on lines +153 to +156
# Merge user-defined env from metadata with any env_vars from options
env_vars = dict(metadata.env) if metadata.env else {}
if options.get('env_vars'):
env_vars.update(options['env_vars'])
Comment on lines +237 to +240
# Merge user-defined env from metadata with any env_vars from options
env_vars = dict(metadata.env) if metadata.env else {}
if options.get('env_vars'):
env_vars.update(options['env_vars'])
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 10, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.75%. Comparing base (524e55e) to head (d8f9bc2).
⚠️ Report is 29 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #315      +/-   ##
==========================================
+ Coverage   47.57%   47.75%   +0.18%     
==========================================
  Files          30       30              
  Lines        2819     2854      +35     
==========================================
+ Hits         1341     1363      +22     
- Misses       1338     1343       +5     
- Partials      140      148       +8     
Flag Coverage Δ
unittests 47.75% <ø> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@madmecodes madmecodes force-pushed the feat/env-support-metadata branch from 74413a8 to c8f5957 Compare May 10, 2026 18:13
Copilot AI review requested due to automatic review settings May 10, 2026 18:21
@madmecodes madmecodes force-pushed the feat/env-support-metadata branch from c8f5957 to 4927514 Compare May 10, 2026 18:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

Comment on lines +155 to +156
if options.get('env_vars'):
env_vars.update(options['env_vars'])
Comment on lines +237 to +240
# Merge user-defined env from metadata with any env_vars from options
env_vars = dict(metadata.env) if metadata.env else {}
if options.get('env_vars'):
env_vars.update(options['env_vars'])
Comment on lines +72 to +75
# User-defined environment variables injected into sandbox pods
env: Optional[Dict[str, str]] = Field(
None, description="Extra env vars to inject into the agent container"
)
Comment on lines +180 to +185
passed_env = call_kwargs.kwargs.get("env_vars") or call_kwargs[1].get("env_vars")
assert passed_env is not None
assert "LLM_BASE_URL" in passed_env
assert passed_env["LLM_BASE_URL"] == "http://llm"
assert passed_env["LLM_API_KEY"] == "sk-123"

@madmecodes madmecodes force-pushed the feat/env-support-metadata branch from 4927514 to ba4a7ba Compare May 11, 2026 02:53
Signed-off-by: madmecodes <ayushguptadev1@gmail.com>
Copy link
Copy Markdown
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Should we update document as well like docs/design/AgentRun-CLI-Design.md

@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hzxuzhonghu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hzxuzhonghu
Copy link
Copy Markdown
Member

LLM_API_KEY should better reference a secret key in k8s spec

@volcano-sh-bot volcano-sh-bot merged commit abb1bf3 into volcano-sh:main May 11, 2026
14 checks passed
@warjiang
Copy link
Copy Markdown
Contributor

🚀 cool, need this feature ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add env support in agent_metadata.yaml

6 participants