feat(agent): add task-oriented run logs and execution details

This commit is contained in:
RockChinQ
2026-09-18 00:59:17 +08:00
parent b264d46d77
commit a6ac25cf84
20 changed files with 1080 additions and 11 deletions
@@ -83,6 +83,7 @@ class AgentRunJournal:
run_id=context['run_id'],
event_id=event.event_id,
binding_id=binding.binding_id,
agent_id=binding.agent_id,
runner_id=descriptor.id,
conversation_id=event.conversation_id,
thread_id=event.thread_id,
@@ -100,6 +101,19 @@ class AgentRunJournal:
if binding.processor_type == 'event_processor'
else {}
),
**(
{
**({'input_event': event.data} if event.event_type != 'message.received' else {}),
'input': {
'text': context.get('input', {}).get('text', ''),
'contents': self._sanitize_contents(context.get('input', {}).get('contents', [])),
'attachments': self._sanitize_attachments(context.get('input', {}).get('attachments', [])),
},
'delivery': event.delivery.model_dump(mode='json'),
}
if binding.processor_type == 'agent'
else {}
),
},
)
@@ -636,6 +636,7 @@ class RunLedgerStore:
strict_thread: bool = False,
runner_id: str | None = None,
binding_id: str | None = None,
agent_id: str | None = None,
) -> tuple[list[dict[str, typing.Any]], int | None, bool, int]:
"""Page runs by scope.
@@ -643,9 +644,21 @@ class RunLedgerStore:
Tuple of (items, next_cursor, has_more, total_count).
"""
limit = min(max(int(limit), 1), 100)
agent_filter = sqlalchemy.or_(
AgentRun.agent_id == agent_id,
sqlalchemy.and_(
AgentRun.agent_id.is_(None),
sqlalchemy.or_(
AgentRun.binding_id.startswith(f'agent_{agent_id}_', autoescape=True),
AgentRun.binding_id.startswith(f'debug:{agent_id}:', autoescape=True),
),
),
)
async with self._session_factory() as session:
# First get total count
count_query = sqlalchemy.select(sqlalchemy.func.count(AgentRun.id))
if agent_id is not None:
count_query = count_query.where(agent_filter)
if conversation_id is not None:
count_query = count_query.where(AgentRun.conversation_id == conversation_id)
if statuses:
@@ -660,6 +673,8 @@ class RunLedgerStore:
# Then get items
query = sqlalchemy.select(AgentRun)
if agent_id is not None:
query = query.where(agent_filter)
if conversation_id is not None:
query = query.where(AgentRun.conversation_id == conversation_id)
if statuses: