Skip to content

prompt hook does not carry the agent id #54896

Open

Description

@osrt91

What happens

The prompt session hook does not carry the agent id, so a plugin that needs to route per agent cannot identify which agent is running at the point where routing can still be changed.

Observed

[prompt] event.agent   = undefined
[prompt] event.delivery = steer

This matches SessionPrompt in @opencode/[email protected]:

export interface SessionPrompt {
    readonly sessionID: Session.ID;
    readonly messageID: SessionMessage.ID;
    prompt: DeepMutable<PromptInput.Prompt>;
    metadata?: Record<string, unknown>;
    delivery: SessionInbox.Delivery;
}

No agent, and PromptInput.Prompt carries only text, files, agents, skills — no model or agent override.

Other hooks do carry it

[context]       agent=Astra-Plan  model=opencode-go/longcat-2.5-preview-free
[model.request] agent=Astra-Plan  model=opencode-go/longcat-2.5-preview-free  kind=primary

Timing matters

Hook order for a primary turn is:

prompt → model.request(kind=title) → context → model.request(kind=primary)

prompt is the earliest hook, and the only one where the session model is not yet frozen — context and model.request both declare readonly model. So prompt is the only place a plugin could redirect a turn to another model.

Today, working around this requires reading session.agent (see #54895) — which is possible — but the agent field on the event itself would be more direct.

Suggestion

Add readonly agent: Agent.ID to SessionPrompt.

Environment

opencode v2.0.27, @opencode/plugin 2.0.27.

Activity

  1. opencode-agent commented on Oct 12, 2026

    @opencode-agent
    Contributor

    Thanks for the clear write-up! To restate the request: the prompt hook event (SessionPrompt) should include readonly agent: Agent.ID. prompt is the earliest hook and the last point before the turn's model is fixed, so a plugin routing by agent could identify the agent there without calling ctx.session.get({ sessionID }) first. That workaround does work in the meantime, as you noted.

    I checked the current code and SessionPrompt in @opencode/plugin still has no agent field, while context and model.request do carry it. Maintainers will consider adding it.

    Related issues:

  2. 56wj commented on Oct 14, 2026

    @56wj

    I'd like to work on this. I propose adding readonly agent: Agent.ID to both SessionPrompt interfaces, populating it during prompt preparation, and adding regression tests. This only exposes agent identity, without changing model selection or routing. Could you approve this scope and assign it to @56wj? I'll wait for design approval before opening a PR.

  3. osrt91 commented on Oct 14, 2026

    @osrt91
    Author

    The proposed scope is right. Please add readonly agent: Agent.ID to both SessionPrompt interfaces, fill it while the prompt is prepared, and cover it with a regression test.

    This should only expose the agent identity. It should not change model selection or routing. Assigning it to @56wj is fine. A PR with that scope is welcome.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions