improve agent context inheritance
This commit is contained in:
parent
6c85a39bbb
commit
9403b8c57f
|
|
@ -23,12 +23,8 @@ class AgentContext:
|
||||||
self.completion_message = ""
|
self.completion_message = ""
|
||||||
self.agent_should_exit = False
|
self.agent_should_exit = False
|
||||||
|
|
||||||
# Inherit state from parent if provided
|
# Note: Completion flags (task_completed, plan_completed, completion_message,
|
||||||
if parent_context:
|
# agent_should_exit) are no longer inherited from parent contexts
|
||||||
self.task_completed = parent_context.task_completed
|
|
||||||
self.plan_completed = parent_context.plan_completed
|
|
||||||
self.completion_message = parent_context.completion_message
|
|
||||||
self.agent_should_exit = parent_context.agent_should_exit
|
|
||||||
|
|
||||||
def mark_task_completed(self, message: str) -> None:
|
def mark_task_completed(self, message: str) -> None:
|
||||||
"""Mark the current task as completed.
|
"""Mark the current task as completed.
|
||||||
|
|
|
||||||
|
|
@ -221,12 +221,12 @@ class TestAgentContext:
|
||||||
assert context.completion_message == ""
|
assert context.completion_message == ""
|
||||||
|
|
||||||
def test_context_inheritance(self):
|
def test_context_inheritance(self):
|
||||||
"""Test that child contexts inherit state from parent contexts."""
|
"""Test that child contexts do not inherit completion flags from parent contexts."""
|
||||||
parent = AgentContext()
|
parent = AgentContext()
|
||||||
parent.mark_task_completed("Parent task completed")
|
parent.mark_task_completed("Parent task completed")
|
||||||
child = AgentContext(parent_context=parent)
|
child = AgentContext(parent_context=parent)
|
||||||
assert child.task_completed is True
|
assert child.task_completed is False
|
||||||
assert child.completion_message == "Parent task completed"
|
assert child.completion_message == ""
|
||||||
|
|
||||||
def test_mark_task_completed(self):
|
def test_mark_task_completed(self):
|
||||||
"""Test marking a task as completed."""
|
"""Test marking a task as completed."""
|
||||||
|
|
@ -290,16 +290,16 @@ class TestContextManager:
|
||||||
parent = AgentContext()
|
parent = AgentContext()
|
||||||
parent.mark_task_completed("Parent task")
|
parent.mark_task_completed("Parent task")
|
||||||
with agent_context(parent_context=parent) as ctx:
|
with agent_context(parent_context=parent) as ctx:
|
||||||
assert ctx.task_completed is True
|
assert ctx.task_completed is False
|
||||||
assert ctx.completion_message == "Parent task"
|
assert ctx.completion_message == ""
|
||||||
|
|
||||||
def test_context_manager_inheritance(self):
|
def test_context_manager_inheritance(self):
|
||||||
"""Test that nested contexts inherit from outer contexts by default."""
|
"""Test that nested contexts do not inherit completion flags from outer contexts."""
|
||||||
with agent_context() as outer:
|
with agent_context() as outer:
|
||||||
outer.mark_task_completed("Outer task")
|
outer.mark_task_completed("Outer task")
|
||||||
with agent_context() as inner:
|
with agent_context() as inner:
|
||||||
assert inner.task_completed is True
|
assert inner.task_completed is False
|
||||||
assert inner.completion_message == "Outer task"
|
assert inner.completion_message == ""
|
||||||
inner.mark_plan_completed("Inner plan")
|
inner.mark_plan_completed("Inner plan")
|
||||||
# Outer context should not be affected by inner context changes
|
# Outer context should not be affected by inner context changes
|
||||||
assert outer.task_completed is True
|
assert outer.task_completed is True
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,12 @@ class TestAgentContext:
|
||||||
assert context.completion_message == ""
|
assert context.completion_message == ""
|
||||||
|
|
||||||
def test_context_inheritance(self):
|
def test_context_inheritance(self):
|
||||||
"""Test that child contexts inherit state from parent contexts."""
|
"""Test that child contexts do not inherit completion flags from parent contexts."""
|
||||||
parent = AgentContext()
|
parent = AgentContext()
|
||||||
parent.mark_task_completed("Parent task completed")
|
parent.mark_task_completed("Parent task completed")
|
||||||
child = AgentContext(parent_context=parent)
|
child = AgentContext(parent_context=parent)
|
||||||
assert child.task_completed is True
|
assert child.task_completed is False
|
||||||
assert child.completion_message == "Parent task completed"
|
assert child.completion_message == ""
|
||||||
|
|
||||||
def test_mark_task_completed(self):
|
def test_mark_task_completed(self):
|
||||||
"""Test marking a task as completed."""
|
"""Test marking a task as completed."""
|
||||||
|
|
@ -96,16 +96,16 @@ class TestContextManager:
|
||||||
parent = AgentContext()
|
parent = AgentContext()
|
||||||
parent.mark_task_completed("Parent task")
|
parent.mark_task_completed("Parent task")
|
||||||
with agent_context(parent_context=parent) as ctx:
|
with agent_context(parent_context=parent) as ctx:
|
||||||
assert ctx.task_completed is True
|
assert ctx.task_completed is False
|
||||||
assert ctx.completion_message == "Parent task"
|
assert ctx.completion_message == ""
|
||||||
|
|
||||||
def test_context_manager_inheritance(self):
|
def test_context_manager_inheritance(self):
|
||||||
"""Test that nested contexts inherit from outer contexts by default."""
|
"""Test that nested contexts do not inherit completion flags from outer contexts."""
|
||||||
with agent_context() as outer:
|
with agent_context() as outer:
|
||||||
outer.mark_task_completed("Outer task")
|
outer.mark_task_completed("Outer task")
|
||||||
with agent_context() as inner:
|
with agent_context() as inner:
|
||||||
assert inner.task_completed is True
|
assert inner.task_completed is False
|
||||||
assert inner.completion_message == "Outer task"
|
assert inner.completion_message == ""
|
||||||
inner.mark_plan_completed("Inner plan")
|
inner.mark_plan_completed("Inner plan")
|
||||||
# Outer context should not be affected by inner context changes
|
# Outer context should not be affected by inner context changes
|
||||||
assert outer.task_completed is True
|
assert outer.task_completed is True
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue