Public/Invoke-AgentHandoff.ps1
|
function Invoke-AgentHandoff { [CmdletBinding()] param( [Parameter(Mandatory, Position = 0)] [hashtable]$Message, [Parameter(Mandatory)] [string]$NextAgent, [string]$ApiKey = $env:HANDOFF_API_KEY, [switch]$VerboseOutput ) if (-not $ApiKey) { throw "Set your API key: `$env:HANDOFF_API_KEY = 'your-key'" } $baseUrl = "https://agent-handoff-production-573c.up.railway.app" $headers = @{ "x-api-key" = $ApiKey; "Content-Type" = "application/json" } $payload = @{ message = $Message next_agent = $NextAgent } | ConvertTo-Json -Depth 10 if ($VerboseOutput) { Write-Host "Sending handoff to agent: $NextAgent..." -ForegroundColor Cyan } try { $response = Invoke-RestMethod -Uri "$baseUrl/handoff" -Method Post ` -Headers $headers -Body $payload -TimeoutSec 30 } catch { throw "Handoff request failed: $_" } if ($VerboseOutput) { Write-Host "Handoff ID : $($response.handoff_id)" -ForegroundColor Gray Write-Host "Success : $($response.success)" -ForegroundColor Green Write-Host "Total : $($response.total_handoffs) handoff(s) processed" -ForegroundColor Gray } return [PSCustomObject]@{ Success = $response.success HandoffId = $response.handoff_id NextAgent = $response.next_agent Timestamp = $response.timestamp TotalHandoffs = $response.total_handoffs IsPro = $response.enriched_metadata.is_pro CleanedMessage = $response.cleaned_message Metadata = $response.enriched_metadata } } function Get-HandoffHealth { $baseUrl = "https://agent-handoff-production-573c.up.railway.app" $response = Invoke-RestMethod -Uri "$baseUrl/health" -Method Get -TimeoutSec 10 return $response } function Get-HandoffStats { param( [Parameter(Mandatory)] [string]$ApiKey ) if (-not $ApiKey) { $ApiKey = $env:HANDOFF_API_KEY } $baseUrl = "https://agent-handoff-production-573c.up.railway.app" $headers = @{ "x-api-key" = $ApiKey } $response = Invoke-RestMethod -Uri "$baseUrl/stats" -Method Get -Headers $headers -TimeoutSec 10 return $response } |