Tool log: persist agent tool calls in messages
Some checks failed
Deploy Tracker / deploy (push) Failing after 3s

- Message model: tool_log JSON column (array of {name, args, result, error})
- chat.send WS handler accepts tool_log
- MessageOut schema includes tool_log
- Converters pass tool_log through
This commit is contained in:
markov 2026-02-27 11:55:14 +01:00
parent f07bbfe6fc
commit ff6b32316c
4 changed files with 9 additions and 1 deletions

View File

@ -84,6 +84,7 @@ def message_out(m: Message) -> MessageOut:
author=member_brief(m.author) if m.author else None,
content=m.content,
thinking=m.thinking,
tool_log=m.tool_log,
mentions=_resolve_mentions(m),
actor=member_brief(m.actor) if hasattr(m, 'actor') and m.actor else None,
voice_url=m.voice_url,

View File

@ -61,6 +61,7 @@ class MessageOut(BaseModel):
author: MemberBrief | None = None
content: str
thinking: str | None = None
tool_log: list[dict] | None = None
mentions: list[MemberBrief] = []
actor: MemberBrief | None = None
voice_url: str | None = None

View File

@ -3,7 +3,7 @@
import uuid
from typing import TYPE_CHECKING
from sqlalchemy import ForeignKey, Integer, String, Text
from sqlalchemy import ForeignKey, Integer, JSON, String, Text
from sqlalchemy.dialects.postgresql import ARRAY, UUID
from sqlalchemy.orm import Mapped, mapped_column, relationship
@ -47,6 +47,9 @@ class Message(Base):
# Actor — who initiated the action (for system messages: who created/moved/assigned the task)
actor_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("members.id"), nullable=True)
# Tool log — JSON array of tool calls [{name, args, result, error?}]
tool_log: Mapped[dict | None] = mapped_column(JSON, nullable=True)
# Content
content: Mapped[str] = mapped_column(Text, nullable=False)
thinking: Mapped[str | None] = mapped_column(Text, nullable=True) # LLM reasoning/thinking block

View File

@ -42,6 +42,7 @@ def _to_message_out(msg: Message, author: Member | None = None) -> MessageOut:
author=_to_member_brief(author) if author else None,
content=msg.content,
thinking=msg.thinking,
tool_log=msg.tool_log,
mentions=mention_briefs,
actor=_to_member_brief(msg.actor) if hasattr(msg, 'actor') and msg.actor else None,
voice_url=msg.voice_url,
@ -287,6 +288,7 @@ async def _handle_chat_send(session_id: str, data: dict):
task_id = data.get("task_id")
content = data.get("content", "")
thinking = data.get("thinking")
tool_log = data.get("tool_log")
mentions = data.get("mentions", [])
if not content:
@ -306,6 +308,7 @@ async def _handle_chat_send(session_id: str, data: dict):
author_id=member.id,
content=content,
thinking=thinking,
tool_log=tool_log,
mentions=mentions,
)
db.add(msg)