Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/Feature/Providers/Anthropic/ToolMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,37 @@
});
});

test('web search tool sends user_location when location is set', function () {
Http::fake([
'api.anthropic.com/*' => $this->fakeTextResponse('ok'),
]);

agent(tools: [(new WebSearch)->location(city: 'Warsaw', country: 'PL')])
->prompt('Search', provider: 'anthropic');

Http::assertSent(function ($request) {
$tool = collect($request->data()['tools'] ?? [])->firstWhere('name', 'web_search');

return data_get($tool, 'user_location.type') === 'approximate'
&& data_get($tool, 'user_location.city') === 'Warsaw'
&& data_get($tool, 'user_location.country') === 'PL';
});
});

test('web search tool omits user_location when no location set', function () {
Http::fake([
'api.anthropic.com/*' => $this->fakeTextResponse('ok'),
]);

agent(tools: [new WebSearch])->prompt('Search', provider: 'anthropic');

Http::assertSent(function ($request) {
$tool = collect($request->data()['tools'] ?? [])->firstWhere('name', 'web_search');

return ! array_key_exists('user_location', $tool);
});
});

test('web fetch tool sends allowed_domains', function () {
Http::fake([
'api.anthropic.com/*' => $this->fakeTextResponse('ok'),
Expand Down