opencode
opencode copied to clipboard
fix(server): inherit agent from previous message in session
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.