Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(agent-chat): replay CLI transcript tool calls as the tool record (#1087)

Ruben Lütkec3c482493b8a
diff --git a/dodaios/agent_chat/dodaios_harness.py b/dodaios/agent_chat/dodaios_harness.py
index d1b764c87b..e3acd561b2 100644
--- a/dodaios/agent_chat/dodaios_harness.py
+++ b/dodaios/agent_chat/dodaios_harness.py
@@ -456,41 +456,30 @@ def render_transcript(
The model reading this IS the second speaker, whatever it is called (the
assistant on the app's own chat, a named agent on its seat), so its own
lines are labelled ``You``. Nothing parses these labels.
+
+ A turn's tool calls appear as the same labelled tool record the in-process
+ brain replays (``runner_brain.brain_history_from_events``): each call with
+ its bounded result, worded as data. A bare "[used tool X]" line without the
+ result taught smaller models to type that line instead of calling the tool
+ (issue #978).
"""
- from dodaios.agent_chat.runner_api import messages_from_events
+ from dodaios.agent_chat.runner_brain import brain_history_from_events
lines: list[str] = []
- for message in messages_from_events(history):
+ for message in brain_history_from_events(history, max_messages=None):
+ text = message.content.strip() if isinstance(message.content, str) else ""
+ if not text:
+ continue
if message.role == "user":
- text = message.content if isinstance(message.content, str) else ""
- if text.strip():
- lines.append(f"Person: {text.strip()}")
+ lines.append(f"Person: {text}")
elif message.role == "assistant":
- text = _prose(message.content)
- if text.strip():
- lines.append(f"You: {text.strip()}")
+ lines.append(f"You: {text}")
out = "\n\n".join(lines)
if len(out) > max_chars:
out = "…" + out[-max_chars:]
return out
-def _prose(content: str | list[dict[str, Any]]) -> str:
- # Only a tool_use block makes a marker; one typed in a reply is an
- # imitation and must not be replayed (see dodaios.brain.tool_marker).
- from dodaios.brain.tool_marker import replay_text
-
- if isinstance(content, str):
- return replay_text(content)
- bits: list[str] = []
- for block in content:
- if block.get("type") == "text":
- bits.append(replay_text(str(block.get("text") or "")))
- elif block.get("type") == "tool_use":
- bits.append(f"[used tool {block.get('name') or 'tool'}]")
- return "\n".join(b for b in bits if b.strip())
-
-
def _preamble_of(text: str) -> str:
"""The closing preamble an identity ends with (a society seat's or the assistant's)."""
return SOCIETY_PREAMBLE if text.endswith(SOCIETY_PREAMBLE) else SYSTEM_PREAMBLE
diff --git a/tests/unit/agent_chat/test_transcript_tool_record.py b/tests/unit/agent_chat/test_transcript_tool_record.py
new file mode 100644
index 0000000000..aecc3111ea
--- /dev/null
+++ b/tests/unit/agent_chat/test_transcript_tool_record.py
@@ -0,0 +1,85 @@
+"""The replayed CLI transcript records tool calls as labelled data (#978).
+
+A bare "[used tool X]" line with no result taught smaller models to type that
+line instead of calling the tool. The transcript a CLI seat reads on a fresh
+conversation now carries the same tool record the in-process brain replays.
+"""
+
+from __future__ import annotations
+
+from typing import Any
+
+from dodaios.agent_chat.dodaios_harness import render_transcript
+from dodaios.agent_chat.events import make_event
+
+
+def _ev(seq: int, kind: str, payload: dict[str, Any]) -> dict[str, Any]:
+ event = make_event(kind, payload)
+ event["seq"] = seq
+ return event
+
+
+def _history() -> list[dict[str, Any]]:
+ return [
+ _ev(1, "user_message", {"text": "What is in notes.txt?"}),
+ _ev(
+ 2,
+ "tool_call",
+ {"turn_id": "t", "call_id": "c0", "name": "Read", "input": {"file_path": "notes.txt"}},
+ ),
+ _ev(
+ 3,
+ "tool_result",
+ {"turn_id": "t", "call_id": "c0", "output": "buy milk", "is_error": False},
+ ),
+ _ev(
+ 4,
+ "tool_call",
+ {
+ "turn_id": "t",
+ "call_id": "c1",
+ "name": "Bash",
+ "input": {"command": "cat missing.txt"},
+ },
+ ),
+ _ev(
+ 5,
+ "tool_result",
+ {"turn_id": "t", "call_id": "c1", "output": "no such file", "is_error": True},
+ ),
+ _ev(6, "assistant_text", {"turn_id": "t", "text": "It says: buy milk."}),
+ _ev(7, "turn_finished", {"turn_id": "t", "status": "done"}),
+ _ev(8, "user_message", {"text": "Thanks"}),
+ ]
+
+
+def test_the_transcript_carries_the_tool_record_not_a_bare_marker() -> None:
+ out = render_transcript(_history())
+ assert "[used tool" not in out
+ assert "Tool record of this turn" in out
+ assert "returned: buy milk" in out
+ assert "failed: no such file" in out
+
+
+def test_one_turn_is_one_line_of_the_second_speaker() -> None:
+ out = render_transcript(_history())
+ blocks = out.split("\n\n")
+ assert blocks[0] == "Person: What is in notes.txt?"
+ assert blocks[1].startswith("You: Tool record of this turn")
+ assert blocks[1].endswith("It says: buy milk.")
+ assert blocks[2] == "Person: Thanks"
+
+
+def test_a_typed_marker_in_a_reply_is_not_replayed_as_a_call() -> None:
+ history = [
+ _ev(1, "user_message", {"text": "play music"}),
+ _ev(2, "assistant_text", {"turn_id": "t", "text": "[used tool play_music] Playing now."}),
+ _ev(3, "turn_finished", {"turn_id": "t", "status": "done"}),
+ ]
+ assert "[used tool play_music]" not in render_transcript(history)
+
+
+def test_the_transcript_is_cut_from_the_front() -> None:
+ history = [_ev(1, "user_message", {"text": "x" * 500})]
+ out = render_transcript(history, max_chars=100)
+ assert out.startswith("…") and len(out) == 101