surfaces/.planning/phases/04-matrix-mvp-shared-agent-context-and-context-management-comma/.continue-here.md

3 KiB
Raw Blame History

context phase task total_tasks status last_updated
phase 04-matrix-mvp-shared-agent-context-and-context-management-comma 4 6 in_progress 2026-04-24T12:16:09.301Z

<current_state> Debugging first-chunk truncation bug in Matrix bot. Logging added to both sdk/real.py and external/platform-agent/src/agent/service.py. Waiting for user to run docker compose up --build and share platform-agent logs with stream_event lines. </current_state>

<completed_work>

  • docker-compose.yml: added ./config:/app/config:ro volume mount so MATRIX_AGENT_REGISTRY_PATH works
  • config/matrix-agents.example.yaml: updated labels to Platform/Media
  • sdk/real.py: added structlog debug logging in _stream_agent_events (logs each chunk index + text[:40])
  • external/platform-agent/src/agent/service.py: added logging of langgraph_node, content_type, content[:60] for every on_chat_model_stream event

Bot is running and user confirmed it starts correctly with MATRIX_PLATFORM_BACKEND=real. </completed_work>

<remaining_work>

  • Task 4: Get platform-agent debug logs (docker compose up --build, reproduce truncation, share stream_event lines)
  • Task 5: Analyze: check content_type (str vs list), check langgraph_node (which graph node produces the first chunk)
  • Task 6: Fix service.py based on findings </remaining_work>

<decisions_made>

  • Bug confirmed to be in platform-agent, NOT in surfaces bot: our sdk/real.py logs show chunk index=0 already has truncated text (e.g. ' Д Е Ё...' instead of 'А Б В Г Д...')
  • deepagents framework uses SubAgentMiddleware: main dispatcher agent + general-purpose subagent
  • service.py processes ALL on_chat_model_stream events from astream_events v2 with no node filtering
  • Two leading hypotheses: (A) chunk.content is a list for some events (multimodal), causing silent skip/error; (B) events from wrong graph node are being captured/not captured </decisions_made>
- Need user to run docker compose up --build and share platform-agent logs with DEBUG output The deepagents architecture: create_deep_agent creates a main orchestrator with SubAgentMiddleware wrapping a general-purpose subagent. When astream_events v2 runs, it may emit on_chat_model_stream from both the main agent's LLM call AND the subagent's LLM call. service.py captures ALL of them. The first chunk of the actual response might be from the subagent (not forwarded to client properly), while the main agent's response starts mid-sentence because it "sees" the subagent's output in its tool result context.

Two key things to look for in logs:

  1. content_type=list → fix is chunk.content[0].get("text", "") or similar
  2. langgraph_node varies between chunks → fix is to filter to the correct node (e.g. only "agent" node)

<next_action> Start with: docker compose up --build. Then send a message with image context (e.g. send an image first, then ask 'Напомни алфавит'). Share platform-agent-1 logs — specifically the stream_event lines showing ns= and content_type= values. </next_action>