Skip to content

The agent that grows with you

fix(agent): thread turn_author through conversation_loop.run_conversation

Teknium94f77dfa0d2c
diff --git a/agent/conversation_loop.py b/agent/conversation_loop.py
index 480a592b25b..f27245eba49 100644
--- a/agent/conversation_loop.py
+++ b/agent/conversation_loop.py
@@ -1581,6 +1581,7 @@ def run_conversation(
persist_user_display_metadata: Optional[Dict[str, Any]] = None,
persist_user_platform_id: Optional[str] = None,
moa_config: Optional[dict[str, Any]] = None,
+ turn_author: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
"""Run one turn (see ``_run_conversation_turn``) and export the current-turn boundary.
@@ -1604,6 +1605,7 @@ def run_conversation(
persist_user_display_metadata=persist_user_display_metadata,
persist_user_platform_id=persist_user_platform_id,
moa_config=moa_config,
+ turn_author=turn_author,
)
return export_current_turn_boundary(agent, result, user_message)
diff --git a/tests/agent/test_turn_context.py b/tests/agent/test_turn_context.py
index 622d2fed203..a08d6665e2b 100644
--- a/tests/agent/test_turn_context.py
+++ b/tests/agent/test_turn_context.py
@@ -320,6 +320,31 @@ def test_turn_without_author_clears_previous_bot_author():
assert kwargs["author_is_bot"] is False
+def test_turn_author_reaches_the_agent_through_the_real_facade(monkeypatch):
+ """``AIAgent.run_conversation(turn_author=...)`` crosses the facade and the loop entry point, not only
+ ``build_turn_context``; a kwarg dropped at either hop raised TypeError on every real turn."""
+ from types import SimpleNamespace
+ from run_agent import AIAgent
+
+ class _Completions:
+ def create(self, **_kw):
+ return SimpleNamespace(choices=[SimpleNamespace(
+ message=SimpleNamespace(content="ok", tool_calls=None, reasoning=None, reasoning_content=None),
+ finish_reason="stop")], usage=None, model="test-model")
+
+ monkeypatch.setattr("agent.process_bootstrap.OpenAI",
+ lambda **_kw: SimpleNamespace(chat=SimpleNamespace(completions=_Completions())))
+ monkeypatch.setattr("model_tools.get_tool_definitions", lambda *a, **k: [])
+ agent = AIAgent(model="test-model", api_key="k", base_url="http://localhost:1/v1", platform="cli",
+ max_iterations=2, quiet_mode=True, skip_memory=True)
+ agent._disable_streaming = True
+
+ agent.run_conversation("hi", turn_author={"id": "bot:alpha", "name": "Alpha", "is_bot": True})
+ assert agent._turn_author == {"id": "bot:alpha", "name": "Alpha", "is_bot": True}
+ agent.run_conversation("hi again")
+ assert agent._turn_author is None
+
+
def test_turn_start_replaces_stale_parent_history_with_compression_child():
agent = _FakeAgent()
stale_history = [{"role": "user", "content": "stale parent"}]