GeezerVison is showing github.com — fix(cli): load the agent's .env into locally run ACP and worker processes by michaelxu2288 · Pull Request #515 · scaleapi/scale-agentex-python
Conversation
Problem
getting_started/project_structure.md says a .env next to manifest.yaml "is automatically loaded when placed alongside your manifest.yaml file, but only for local development". Nothing does that today:
agentex agents run builds the child environment from os.environ plus the manifest (create_agent_environment).
EnvironmentVariables.refresh() loads .env from Path(__file__).parents[2], which is site-packages for an installed SDK, never the agent folder, and .env.local from cwd.parent.
ProjectConfigLoader._load_env only feeds config templating.
Values from .env reach a process only when some import happens to call load_dotenv() first. litellm does, on import (litellm/__init__.py), which is why the Temporal + OpenAI Agents template appears to work (its model client is built lazily inside the activity, after imports) while Temporal + Pydantic AI fails at import time of project/agent.py with openai.OpenAIError: Missing credentials. Verified with a print at the top of both workers: OpenAI Agents worker sees LITELLM_API_KEY only after its imports; the Pydantic AI worker never does.
Fix
create_agent_environment(manifest, manifest_dir) merges <manifest dir>/.env (python-dotenv dotenv_values, already a dependency) into the environment handed to both the ACP and worker subprocesses, without overriding variables already set in the shell (python-dotenv semantics). run_agent passes manifest_file.parent. 16-line diff plus three tests (merge, shell precedence, no file / no manifest_dir) that render a real manifest via the init helpers.
Verification
tests/lib/cli/test_run_handlers_env.py: 3 passed; streaming handler tests still pass; ruff clean.
- Live, Temporal + Pydantic AI scaffold with only
LITELLM_API_KEY in .env, patched SDK installed into its venv: before, no reply and Missing credentials; after, reply in 4.7 s, zero worker errors.
Pairs with #514 ("fix(templates): map LITELLM_API_KEY to OPENAI_API_KEY in Temporal workers"): once .env is in the process environment from the start, that mapping at the top of run_worker.py becomes deterministic instead of depending on import order.
Confidence Score: 3/5
The PR is not ready to merge while .env can replace manifest-derived settings and deployed agents are missing from metadata-filtered lists.
Findings
Dotenv overrides manifest settings ▶
Fix with agent prompt
### Issue 1
src/agentex/lib/cli/handlers/run_handlers.py:476-478
A `.env` entry can now overwrite manifest-derived runtime settings such as `AGENT_NAME`, `ACP_PORT`, `WORKFLOW_TASK_QUEUE`, and `HEALTH_CHECK_PORT`. These values are added through `env_vars`, but `manifest_env` contains only the explicit `agent.env` mapping. A conflicting dotenv value therefore replaces the manifest-derived value and can start the ACP or worker with the wrong identity, port, task queue, or health-check configuration. Preserve all manifest-derived keys while still allowing `.env` to replace built-in local defaults.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
Local agent runs now load .env from beside manifest.yaml into both child processes, and ACP task creation waits for its handler before replying. The PR also changes the production API URL and updates release, contributor, and security-scan workflows.
- Keeps local process settings consistent while respecting shell and manifest overrides.
- Makes a created task available before callers send events.
- Moves release and repository automation to the
main-based workflow.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
M[manifest.yaml] --> E[Local environment]
D[.env] --> E
S[Shell variables] --> E
E --> A[ACP process]
E --> W[Worker process]
Loading
Reviews (3) · Last reviewed commit: "fix(cli): apply .env after the built-in ..."
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
greptile-apps[bot] reacted with thumbs up emoji
Uh oh!
There was an error while loading. Please reload this page.
michaelxu2288
added a commit
to michaelxu2288/scale-agentex-python
that referenced
this pull request
Sep 10, 2026
…apping the key
The worker is a separate process and agents run does not load the project
.env into it today, so the LITELLM_API_KEY -> OPENAI_API_KEY mapping ran
against an empty environment. Call load_dotenv() first (as acp.py already
does), so the template works on its own; scaleapi#515 makes the CLI load .env for
both processes as well.
Claude-Session: https://claude.ai/code/session_01HCVKnA7LeJZ44nxZz1uzF3
Comment on lines
+476
to
+478
|
|
if key in os.environ or key in manifest_env:
|
|
|
continue
|
|
|
env[key] = value
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dotenv overrides manifest settings
A .env entry can now overwrite manifest-derived runtime settings such as AGENT_NAME, ACP_PORT, WORKFLOW_TASK_QUEUE, and HEALTH_CHECK_PORT. These values are added through env_vars, but manifest_env contains only the explicit agent.env mapping. A conflicting dotenv value therefore replaces the manifest-derived value and can start the ACP or worker with the wrong identity, port, task queue, or health-check configuration. Preserve all manifest-derived keys while still allowing .env to replace built-in local defaults.
Knowledge Base Used: Command-line workflows
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agentex/lib/cli/handlers/run_handlers.py
Line: 476-478
Comment:
**Dotenv overrides manifest settings**
A `.env` entry can now overwrite manifest-derived runtime settings such as `AGENT_NAME`, `ACP_PORT`, `WORKFLOW_TASK_QUEUE`, and `HEALTH_CHECK_PORT`. These values are added through `env_vars`, but `manifest_env` contains only the explicit `agent.env` mapping. A conflicting dotenv value therefore replaces the manifest-derived value and can start the ACP or worker with the wrong identity, port, task queue, or health-check configuration. Preserve all manifest-derived keys while still allowing `.env` to replace built-in local defaults.
**Knowledge Base Used:** [Command-line workflows](https://app.greptile.com/scale-ai/-/custom-context/knowledge-base/scaleapi/scale-agentex-python/-/docs/command-line-workflows.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…sses
The docs say a .env next to manifest.yaml is loaded automatically for local
development, but nothing did: agentex agents run built the child environment
from os.environ plus the manifest, and EnvironmentVariables.refresh() looks
for .env two directories above the installed module (site-packages), never
the agent folder. Values in .env only reached a process when some import
happened to call load_dotenv() first (litellm does, on import). That is why
the OpenAI Agents Temporal template worked (its model client is built lazily
after imports) while the Pydantic AI one failed at import time with
openai.OpenAIError: Missing credentials.
Merge <manifest dir>/.env into the environment handed to both the ACP and
worker subprocesses, without overriding variables already set in the shell
(python-dotenv semantics). Add tests for merge, shell precedence, and the
no-file / no-manifest_dir cases.
Claude-Session: https://claude.ai/code/session_01HCVKnA7LeJZ44nxZz1uzF3
Loading .env before env_vars meant env.update(env_vars) clobbered any
overlapping key, so a custom REDIS_URL or TEMPORAL_ADDRESS in .env had no
effect. Apply .env after the defaults, below the manifest env block and the
shell, and keep ENVIRONMENT pinned to development; add a regression test.
Claude-Session: https://claude.ai/code/session_01HCVKnA7LeJZ44nxZz1uzF3
michaelxu2288
added a commit
to michaelxu2288/scale-agentex-python
that referenced
this pull request
Oct 1, 2026
…apping the key
The worker is a separate process and agents run does not load the project
.env into it today, so the LITELLM_API_KEY -> OPENAI_API_KEY mapping ran
against an empty environment. Call load_dotenv() first (as acp.py already
does), so the template works on its own; scaleapi#515 makes the CLI load .env for
both processes as well.
Claude-Session: https://claude.ai/code/session_01HCVKnA7LeJZ44nxZz1uzF3
This branch has not been deployed
No deployments
Reviewers
At least 1 approving review is required to merge this pull request.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|