deerflow2/backend/packages/harness/deerflow
yangzheli 78633c69ac
fix(agents): propagate agent_name into ToolRuntime.context for setup_agent (#2679)
* fix(agents): propagate agent_name into ToolRuntime.context for setup_agent (#2677)

When creating a custom agent via the web UI, SOUL.md was always written
to the global base_dir/SOUL.md instead of agents/<name>/SOUL.md.

Root cause: the bootstrap flow sends agent_name via body.context, but
two layers were broken:

1. services.py only forwarded body.context keys into config["configurable"];
   config["context"] was never populated.
2. worker.py constructed the parent Runtime with a hard-coded
   {thread_id, run_id} context, ignoring config["context"] entirely.

After the langgraph >= 1.1.9 bump (#98a5b34f), ToolRuntime.context no
longer falls back to configurable, so setup_agent's
runtime.context.get("agent_name") returned None and the tool's silent
agent_name=None -> base_dir fallback kicked in, overwriting the global
SOUL.md.

Fix:
- services.py: extract merge_run_context_overrides() and write the
  whitelisted context keys into both configurable (legacy readers) and
  context (langgraph 1.1+ ToolRuntime consumers).
- worker.py: extract _build_runtime_context() and merge config["context"]
  into the Runtime's context (without letting callers override
  thread_id/run_id).

The base_dir fallback in setup_agent_tool.py is left in place because
the IM /bootstrap channel command depends on it. That code path can
be tightened in a follow-up.

Adds regression tests covering both helpers.

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-05-01 16:00:11 +08:00
..
agents fix: keep lead agent graph factory signature compatible (#2678) 2026-05-01 15:43:28 +08:00
community [security] fix(sandbox): bind local Docker ports to loopback (#2633) 2026-04-30 11:40:28 +08:00
config refactor(skills): Unified skill storage capability (#2613) 2026-05-01 13:23:26 +08:00
guardrails feat(guardrails): add pre-tool-call authorization middleware with pluggable providers (#1240) 2026-03-23 18:07:33 +08:00
mcp feat(mcp): support custom tool interceptors via extensions_config.json (#2451) 2026-04-25 09:18:13 +08:00
models Merge branch 'main' into release/2.0-rc 2026-04-28 15:44:02 +08:00
persistence fix the lint error of backend 2026-04-26 22:16:04 +08:00
reflection refactor: split backend into harness (deerflow.*) and app (app.*) (#1131) 2026-03-14 22:55:52 +08:00
runtime fix(agents): propagate agent_name into ToolRuntime.context for setup_agent (#2679) 2026-05-01 16:00:11 +08:00
sandbox Merge branch 'main' into release/2.0-rc 2026-04-28 15:44:02 +08:00
skills refactor(skills): Unified skill storage capability (#2613) 2026-05-01 13:23:26 +08:00
subagents refactor(skills): Unified skill storage capability (#2613) 2026-05-01 13:23:26 +08:00
tools refactor(skills): Unified skill storage capability (#2613) 2026-05-01 13:23:26 +08:00
tracing feat(tracing): add optional Langfuse support (#1717) 2026-04-02 13:06:10 +08:00
uploads feat(persistence): per-user filesystem isolation, run-scoped APIs, and state/history simplification (#2153) 2026-04-26 11:13:01 +08:00
utils [security] fix(uploads): require explicit opt-in for host-side document conversion (#2332) 2026-04-18 22:47:42 +08:00
__init__.py refactor: split backend into harness (deerflow.*) and app (app.*) (#1131) 2026-03-14 22:55:52 +08:00
client.py refactor(skills): Unified skill storage capability (#2613) 2026-05-01 13:23:26 +08:00