Skip to content

Structured conversation context for pi tasks #9

Description

@AlephNotation

Problem

contextFor() in tree.ts flattens the conversation history into a text blob:

[system] You are reef...
[user] What is 2+2?
[tool] bash
[result] 4
[assistant] The answer is 4.

This gets injected via --append-system-prompt as a single string. The LLM sees it as unstructured text rather than proper conversation turns. Tool call params and full results are lost.

Proposal

  1. Add contextForStructured(nodeId) to tree.ts — returns an array of {role, content, toolCalls?, toolCallId?} objects preserving full tool_call/tool_result pairs
  2. Reef writes structured context to a temp file before spawning pi
  3. A pi extension reads the file on before_agent_start / context event and injects proper structured messages

This gives the LLM:

  • Distinct role boundaries (user/assistant/tool)
  • Full tool call params and results
  • Better context window utilization (no wasted tokens on [tag] prefixes)

Key pi extension hooks

  • before_agent_start — can inject messages and modify system prompt
  • context — can modify the full message array before each LLM call
  • pi.sendMessage() — inject custom messages into the session

References

  • src/tree.tscontextFor() method
  • src/reef.tsspawnTask() uses --append-system-prompt
  • Pi extension docs: before_agent_start, context events

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions