fix(agent): thread turn_author through conversation_loop.run_conversation
The facade forwarded turn_author= to the loop's public entry point, which did not declare it: every real AIAgent.run_conversation() turn raised TypeError (16 CI failures across provider, sidecar, cron and finite-chat suites). The PR's tests only exercised build_turn_context directly, so the missing hop was invisible. Adds one facade-through-loop test that goes red when the kwarg is dropped.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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"}]
|
||||
|
||||
Reference in New Issue
Block a user