php-agentic/Mcp/Tools/Agent/Session/SessionHandoff.php
Snider ad83825f93 refactor: rename namespace Core\Agentic to Core\Mod\Agentic
Updates all classes to use the new modular namespace convention.
Adds Service/ layer with Core\Service\Agentic for service definition.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 16:12:58 +00:00

88 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Mod\Agentic\Mcp\Tools\Agent\Session;
use Core\Mod\Agentic\Models\AgentSession;
use Core\Mod\Agentic\Mcp\Tools\Agent\AgentTool;
/**
* Prepare session for handoff to another agent.
*/
class SessionHandoff extends AgentTool
{
protected string $category = 'session';
protected array $scopes = ['write'];
public function name(): string
{
return 'session_handoff';
}
public function description(): string
{
return 'Prepare session for handoff to another agent';
}
public function inputSchema(): array
{
return [
'type' => 'object',
'properties' => [
'summary' => [
'type' => 'string',
'description' => 'Summary of work done',
],
'next_steps' => [
'type' => 'array',
'description' => 'Recommended next steps',
'items' => ['type' => 'string'],
],
'blockers' => [
'type' => 'array',
'description' => 'Any blockers encountered',
'items' => ['type' => 'string'],
],
'context_for_next' => [
'type' => 'object',
'description' => 'Context to pass to next agent',
],
],
'required' => ['summary'],
];
}
public function handle(array $args, array $context = []): array
{
try {
$summary = $this->require($args, 'summary');
} catch (\InvalidArgumentException $e) {
return $this->error($e->getMessage());
}
$sessionId = $context['session_id'] ?? null;
if (! $sessionId) {
return $this->error('No active session. Call session_start first.');
}
$session = AgentSession::where('session_id', $sessionId)->first();
if (! $session) {
return $this->error('Session not found');
}
$session->prepareHandoff(
$summary,
$this->optional($args, 'next_steps', []),
$this->optional($args, 'blockers', []),
$this->optional($args, 'context_for_next', [])
);
return $this->success([
'handoff_context' => $session->getHandoffContext(),
]);
}
}