assistant: Add basic tool invocation (#17368)

This PR adds the initial groundwork for invoking tools in response to
tool uses from the model.

Tool uses are run when the model responds with a `stop_reason` of
`tool_use`.

Currently the tool results are just inserted as text into the user
message. We'll want to include these as `tool_result` content on the
message, but Claude seems to understand it regardless.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-09-04 14:32:20 -04:00 committed by GitHub
parent 7fb94c4c4d
commit 01525f17fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 92 additions and 10 deletions

View file

@ -66,4 +66,9 @@ impl ToolRegistry {
pub fn tools(&self) -> Vec<Arc<dyn Tool>> {
self.state.read().tools.values().cloned().collect()
}
/// Returns the [`Tool`] with the given name.
pub fn tool(&self, name: &str) -> Option<Arc<dyn Tool>> {
self.state.read().tools.get(name).cloned()
}
}