Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __init__(
"Initial state is not supported per-agent in AgentWorkflow"
)

self.agents = {cfg.name: cfg for cfg in agents}
self.agents = {cfg.name: copy.deepcopy(cfg) for cfg in agents}
if len(agents) == 1:
root_agent = agents[0].name
elif root_agent is None:
Expand Down
20 changes: 20 additions & 0 deletions llama-index-core/tests/agent/workflow/test_multi_agent_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,23 @@ async def test_run_id_default(
assert handler.run_id is not None
assert isinstance(handler.run_id, str)
handler.cancel()


def test_agents_stored_by_deepcopy():
"""Test that AgentWorkflow deepcopies agent configs so two workflows don't share mutable state."""
agent = FunctionAgent(
name="agent",
description="test",
tools=[add],
llm=MockFunctionCallingLLM(),
system_prompt="original",
)

workflow1 = AgentWorkflow(agents=[agent])
workflow2 = AgentWorkflow(agents=[agent])

# Mutate the agent config stored in workflow1
workflow1.agents["agent"].system_prompt = "mutated"

# workflow2 should be unaffected
assert workflow2.agents["agent"].system_prompt == "original"