Skip to content

[Feature]: make read_session tool able to read at offset and/or an agents last message #802

@NamedIdentity

Description

@NamedIdentity

Prerequisites

  • I have searched existing issues and discussions to avoid duplicates
  • This feature request is specific to oh-my-opencode (not OpenCode core)
  • I have read the documentation

Problem Description

The read_session tool can read the entire session, or return a number of messages, but cannot read offsets or the last message in the session. This prevents using the read_session tool to let one agent gain context from subagents responses without reading the entire subagent session.

This becomes a problem in OpenCode builds where subagent to subagent tasking and persistent sessions are used. I introduced a PR to OpenCode with that feature (anomalyco/opencode#7756 (comment)).

Proposed Solution

Update the read_session tool to allow offset reads or reading the last message in a session.

Alternatives Considered

Instruct the Primary agent to use it's in-context memory of subagent responses to write files which it then instructs subagents to read (relay-files). Presumably, writing files from existing text-in-context is less straining on the context window then generating text to send in prompts to subagents via A2A.

Doctor Output (Optional)

Additional Context

The read_session tool having offset reads or last message reads would be generally beneficial. However, it is especially beneficial when subagents can task subagents and maintain persistent sessions.

An example of a subagent-subagent persistent session workflow.

A Primary agent tasks a substantive-work subagent to extract and consolidate data from a corpus in stages. The substantive-work subagent produces multiple consolidated documents. The Primary agent sends one of the documents to be reviewed by a group of review-agents. The review-agents return responses to the Primary. The Primary reports to the user a summary of review-agents findings.

The substantive-work subagent can then be tasked to receive the review-agents responses, but the Primary would have to waste context generating text to relay messages from the review-agents to the substantive-work subagent. Being able to instruct the substantive-work subagent to read the last message in review-agents sessions would efficiently relay responses/data. The substantive-work subagent could then use that data, and it's prior context (it's a persistent session) to determine if the review-agents findings are true, and if so, issue corrections to the document.

Alternative workflow with stateless sessions:

Primary agent tasks to review a corpus of data by tasking multiple subagents. All subagents return response. Primary then instructs on subagent to read_session for all subagent sessions and use that distilled data to perform a task.

This feature is critical to agentic workflows performing data extraction, transformation, and consolidation; to knowledge-work.

Feature Type

New Tool

Contribution

  • I'm willing to submit a PR for this feature
  • I can help with testing
  • I can help with documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions