'object', 'properties' => [ 'session_id' => [ 'type' => 'string', 'description' => 'Session ID to replay from', ], 'agent_type' => [ 'type' => 'string', 'description' => 'Agent type for the new session (defaults to original session\'s agent type)', ], 'context_only' => [ 'type' => 'boolean', 'description' => 'If true, only return the replay context without creating a new session', ], ], 'required' => ['session_id'], ]; } public function handle(array $args, array $context = []): array { try { $sessionId = $this->require($args, 'session_id'); } catch (\InvalidArgumentException $e) { return $this->error($e->getMessage()); } $agentType = $this->optional($args, 'agent_type'); $contextOnly = $this->optional($args, 'context_only', false); return $this->withCircuitBreaker('agentic', function () use ($sessionId, $agentType, $contextOnly) { $sessionService = app(AgentSessionService::class); // If only context requested, return the replay context if ($contextOnly) { $replayContext = $sessionService->getReplayContext($sessionId); if (! $replayContext) { return $this->error("Session not found: {$sessionId}"); } return $this->success([ 'replay_context' => $replayContext, ]); } // Create a new replay session $newSession = $sessionService->replay($sessionId, $agentType); if (! $newSession) { return $this->error("Session not found: {$sessionId}"); } return $this->success([ 'session' => [ 'session_id' => $newSession->session_id, 'agent_type' => $newSession->agent_type, 'status' => $newSession->status, 'plan' => $newSession->plan?->slug, ], 'replayed_from' => $sessionId, 'context_summary' => $newSession->context_summary, ]); }, fn () => $this->error('Agentic service temporarily unavailable.', 'service_unavailable')); } }