pub struct Tool {
pub name: String,
pub description: String,
pub parameters_schema: Value,
}Expand description
Tool definition for registration with a session.
Use the builder pattern to create tools:
use copilot_sdk::{Client, SessionConfig, Tool, ToolHandler, ToolResultObject};
use std::sync::Arc;
#[tokio::main]
async fn main() -> copilot_sdk::Result<()> {
let client = Client::builder().build()?;
client.start().await?;
let tool = Tool::new("get_weather")
.description("Get weather for a city")
.schema(serde_json::json!({
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"]
}));
let session = client.create_session(SessionConfig {
tools: vec![tool.clone()],
..Default::default()
}).await?;
let handler: ToolHandler = Arc::new(|_name, args| {
let city = args.get("city").and_then(|v| v.as_str()).unwrap_or("unknown");
ToolResultObject::text(format!("Weather in {}: sunny", city))
});
session.register_tool_with_handler(tool, Some(handler)).await;
client.stop().await;Fields§
§name: String§description: String§parameters_schema: ValueImplementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Tool
impl RefUnwindSafe for Tool
impl Send for Tool
impl Sync for Tool
impl Unpin for Tool
impl UnsafeUnpin for Tool
impl UnwindSafe for Tool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more