Skip to content

Commit 554258f

Browse files
committed
bug #1170 [Agent][Brave] Make field description optional (daFish)
This PR was merged into the main branch. Discussion ---------- [Agent][Brave] Make field `description` optional | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Docs? | no <!-- required for new features --> | Issues | not applicable <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT The `Brave` tool fails when the Brave Search API returns results without a `description` field. According to the [Brave API documentation](https://api-dashboard.search.brave.com/app/documentation/web-search/responses), the `description` field is **optional**, but the current implementation assumes it's always present. **Error**: `Undefined array key "description"` wrapped in `ToolExecutionException` **User-visible error**: `"An error occurred while executing tool \"brave_search\"."` Commits ------- 6582ae2 fix(brave): make field 'description' nullable
2 parents f857a0a + 6582ae2 commit 554258f

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/agent/src/Bridge/Brave/Brave.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,16 @@ public function __invoke(
7070

7171
foreach ($results as $result) {
7272
$this->addSource(
73-
new Source($result['title'] ?? '', $result['url'] ?? '', $result['description'] ?? '')
73+
new Source($result['title'], $result['url'], $result['description'] ?? '')
7474
);
7575
}
7676

7777
return array_map(static function (array $result) {
78-
return ['title' => $result['title'], 'description' => $result['description'], 'url' => $result['url']];
78+
return [
79+
'title' => $result['title'],
80+
'description' => $result['description'] ?? '',
81+
'url' => $result['url'],
82+
];
7983
}, $data['web']['results'] ?? []);
8084
}
8185
}

src/agent/src/Bridge/Brave/Tests/BraveTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,26 @@ public function testHandlesEmptyResults()
6464

6565
$this->assertEmpty($results);
6666
}
67+
68+
public function testHandlesMissingDescription()
69+
{
70+
$httpClient = new MockHttpClient(new JsonMockResponse([
71+
'web' => [
72+
'results' => [
73+
[
74+
'title' => 'Test Title',
75+
'url' => 'https://example.com',
76+
],
77+
],
78+
],
79+
]));
80+
$brave = new Brave($httpClient, 'test-api-key');
81+
82+
$results = $brave('test query');
83+
84+
$this->assertCount(1, $results);
85+
$this->assertSame('Test Title', $results[0]['title']);
86+
$this->assertSame('', $results[0]['description']);
87+
$this->assertSame('https://example.com', $results[0]['url']);
88+
}
6789
}

0 commit comments

Comments
 (0)