( agentSetting: string | undefined, currentAgentDefinition: AgentDefinition | undefined, agentDefinitions: AgentDefinitionsResult, )
| 198 | * if no agent was restored. |
| 199 | */ |
| 200 | export function restoreAgentFromSession( |
| 201 | agentSetting: string | undefined, |
| 202 | currentAgentDefinition: AgentDefinition | undefined, |
| 203 | agentDefinitions: AgentDefinitionsResult, |
| 204 | ): { |
| 205 | agentDefinition: AgentDefinition | undefined |
| 206 | agentType: string | undefined |
| 207 | } { |
| 208 | // If user already specified --agent on CLI, keep that definition |
| 209 | if (currentAgentDefinition) { |
| 210 | return { agentDefinition: currentAgentDefinition, agentType: undefined } |
| 211 | } |
| 212 | |
| 213 | // If session had no agent, clear any stale bootstrap state |
| 214 | if (!agentSetting) { |
| 215 | setMainThreadAgentType(undefined) |
| 216 | return { agentDefinition: undefined, agentType: undefined } |
| 217 | } |
| 218 | |
| 219 | const resumedAgent = agentDefinitions.activeAgents.find( |
| 220 | agent => agent.agentType === agentSetting, |
| 221 | ) |
| 222 | if (!resumedAgent) { |
| 223 | logForDebugging( |
| 224 | `Resumed session had agent "${agentSetting}" but it is no longer available. Using default behavior.`, |
| 225 | ) |
| 226 | setMainThreadAgentType(undefined) |
| 227 | return { agentDefinition: undefined, agentType: undefined } |
| 228 | } |
| 229 | |
| 230 | setMainThreadAgentType(resumedAgent.agentType) |
| 231 | |
| 232 | // Apply agent's model if user didn't specify one |
| 233 | if ( |
| 234 | !getMainLoopModelOverride() && |
| 235 | resumedAgent.model && |
| 236 | resumedAgent.model !== 'inherit' |
| 237 | ) { |
| 238 | setMainLoopModelOverride(parseUserSpecifiedModel(resumedAgent.model)) |
| 239 | } |
| 240 | |
| 241 | return { agentDefinition: resumedAgent, agentType: resumedAgent.agentType } |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Refresh agent definitions after a coordinator/normal mode switch. |
no test coverage detected