Langertha-Raider

 view release on metacpan or  search on metacpan

t/86_raider_self_tools.t  view on Meta::CPAN

      summary => [ { type => 'summary_text', text => 'Need the weather tool.' } ] },
    { type => 'message', role => 'assistant', status => 'completed',
      content => [ { type => 'output_text', text => 'Checking Hamburg now.' } ] },
    { type => 'function_call', call_id => 'call_1', name => 'get_weather',
      arguments => '{"city":"Hamburg"}' },
    { type => 'function_call_output', call_id => 'call_1',
      output => '[{"text":"Hamburg: rainy, 14C","type":"text"}]' },
    # --- openai: assistant echo has content => undef when it only calls tools ---
    { role => 'assistant', content => undef, tool_calls => [
      { id => 'call_2', type => 'function',
        function => { name => 'get_time', arguments => '{"tz":"CET"}' } },
    ] },
    { role => 'tool', tool_call_id => 'call_2',
      content => '[{"type":"text","text":"14:05"}]' },
    # --- gemini: blocks live under {parts}, there is no {content} at all ---
    { role => 'model', parts => [
      { text => 'One moment.' },
      { functionCall => { name => 'get_weather', args => { city => 'Kiel' } } },
    ] },
    { role => 'user', parts => [
      { functionResponse => { name => 'get_weather',

t/86_raider_self_tools.t  view on Meta::CPAN

  like($text, qr/Berlin: sunny, 22C/, 'anthropic tool_result content flattened to text');

  # responses
  like($text, qr/\[reasoning\] Need the weather tool\./, 'responses reasoning summary rendered');
  like($text, qr/\[assistant\] Checking Hamburg now\./, 'responses message item uses its role');
  like($text, qr/\[function_call\] .*get_weather.*Hamburg/, 'responses function_call labelled by type');
  like($text, qr/\[function_call_output\] .*Hamburg: rainy, 14C/,
    'responses function_call_output labelled by type and carries its output');

  # openai
  like($text, qr/\[assistant\] .*get_time.*CET/, 'openai tool-only assistant echo shows the call');
  like($text, qr/14:05/, 'openai tool result content kept');

  # gemini
  like($text, qr/\[model\] One moment\./, 'gemini text part rendered');
  like($text, qr/get_weather.*Kiel/, 'gemini functionCall part is visible');
  like($text, qr/Kiel: windy, 17C/, 'gemini functionResponse flattened');
};

subtest 'session history query filters on rendered payload' => sub {
  my $raider = Langertha::Raider->new(

t/86_raider_self_tools.t  view on Meta::CPAN

# renders to nothing at all, the responses function_call item has no
# {content} key. Position 2 is anthropic ArrayRef content, which must be
# rendered rather than embedded as "ARRAY(0x...)".
sub embedding_probe_history {
  return (
    { role => 'user', content => 'Aardvark migration question' },
    { role => 'assistant', content => '' },
    { role => 'assistant', content => [
      { type => 'text', text => 'The zebra crossing report' } ] },
    { type => 'function_call', call_id => 'call_9', name => 'get_time',
      arguments => '{"tz":"CET"}' },
    { role => 'assistant', content => 'Narwhal tusk measurements are stable' },
  );
}

subtest 'session embeddings keep one slot per history message' => sub {
  my $embedder = MockEmbeddingEngine->new;
  my $raider = Langertha::Raider->new(
    engine           => MockEngine->new,
    embedding_engine => $embedder,
    raider_mcp       => 1,



( run in 0.599 second using v1.01-cache-2.11-cpan-1bcd28dbaf1 )