Preserve runtime context across LightSwarm handoffs
Problem
LightAgent.run() already accepts runtime context such as user_id, metadata, trace, result_format, max_retry, and max_tool_iterations.
The LightSwarm path currently drops most of that context:
LightSwarm.run(agent, query, stream=False)only forwardsstream.LightAgent._handle_task_transfer()only receivesstream.- Delegated target agents receive
parent_trace_idandrun_group_id, but not the caller'suser_id,metadata, ortrace=True.
This can make delegated runs behave differently from direct agent.run() calls. For example, a user-scoped memory run can hand off to a target agent that falls back to user_id=default_user, and a traced source run may create an untraced target run.
Proposed scope
A small, backward-compatible change:
- allow
LightSwarm.run(..., **run_kwargs)and forward supportedLightAgent.run()options; - pass relevant runtime context through
_handle_task_transfer(); - keep existing
streambehavior unchanged; - add regression tests with a fake target agent to assert
user_id,metadata,trace,parent_trace_id, andrun_group_idpropagation.
This would not merge delegated traces into the parent trace automatically. It would only make the existing explicit trace hierarchy and runtime context available across LightSwarm handoffs.
I can send a focused PR for this if the scope looks reasonable.