[PR #6356] fix(server): inherit agent from previous message in session #11854

Closed
opened 2026-02-16 18:16:47 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6356

State: closed
Merged: No


Summary

  • Fix agent not being inherited across prompts when using the server API

Problem

When using opencode serve and sending prompts via /session/:id/prompt_async, the agent parameter was only used for the first message. Subsequent prompts without an explicit agent defaulted to "build" instead of inheriting the agent from the previous message in the session.

Solution

Added lastAgent() function (similar to existing lastModel()) that looks up the last agent used in the session, and use it as the fallback in createUserMessage() instead of Agent.defaultAgent().

Related to #6160 which fixes the same issue for the TUI.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6356 **State:** closed **Merged:** No --- ## Summary - Fix agent not being inherited across prompts when using the server API ## Problem When using `opencode serve` and sending prompts via `/session/:id/prompt_async`, the `agent` parameter was only used for the first message. Subsequent prompts without an explicit `agent` defaulted to "build" instead of inheriting the agent from the previous message in the session. ## Solution Added `lastAgent()` function (similar to existing `lastModel()`) that looks up the last agent used in the session, and use it as the fallback in `createUserMessage()` instead of `Agent.defaultAgent()`. Related to #6160 which fixes the same issue for the TUI.
yindo added the pull-request label 2026-02-16 18:16:47 -05:00
yindo closed this issue 2026-02-16 18:16:47 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11854