Files
computer/cptr/utils/agents/prompts.py
T
2026-07-18 01:00:12 -04:00

24 lines
673 B
Python

"""Prompt helpers shared by coding agent adapters."""
from __future__ import annotations
from typing import Any
def message_text(message: dict[str, Any]) -> str:
content = message.get("content", "")
if isinstance(content, list):
return "\n".join(
str(block.get("text", "")) for block in content if isinstance(block, dict)
)
return str(content or "")
def latest_user_text(messages: list[dict[str, Any]]) -> str:
"""Return only the current user turn for native-session agents."""
for message in reversed(messages):
if message.get("role") == "user":
return message_text(message).strip()
return ""