pub struct ToolApi<'a> { /* private fields */ }Expand description
Tool API operations.
Implementations§
Source§impl<'a> ToolApi<'a>
impl<'a> ToolApi<'a>
Sourcepub fn new(client: &'a LettaClient) -> Self
pub fn new(client: &'a LettaClient) -> Self
Create a new tool API instance.
Sourcepub async fn list(
&self,
params: Option<ListToolsParams>,
) -> LettaResult<Vec<Tool>>
pub async fn list( &self, params: Option<ListToolsParams>, ) -> LettaResult<Vec<Tool>>
List all tools.
Sourcepub async fn create(&self, request: CreateToolRequest) -> LettaResult<Tool>
pub async fn create(&self, request: CreateToolRequest) -> LettaResult<Tool>
Create a new tool.
Sourcepub async fn get(&self, tool_id: &LettaId) -> LettaResult<Tool>
pub async fn get(&self, tool_id: &LettaId) -> LettaResult<Tool>
Get a specific tool by ID.
Sourcepub async fn update(
&self,
tool_id: &LettaId,
request: UpdateToolRequest,
) -> LettaResult<Tool>
pub async fn update( &self, tool_id: &LettaId, request: UpdateToolRequest, ) -> LettaResult<Tool>
Update a tool.
Sourcepub async fn delete(&self, tool_id: &LettaId) -> LettaResult<()>
pub async fn delete(&self, tool_id: &LettaId) -> LettaResult<()>
Delete a tool.
Sourcepub async fn count(&self) -> LettaResult<u32>
pub async fn count(&self) -> LettaResult<u32>
Get count of tools.
Sourcepub async fn upsert(&self, request: CreateToolRequest) -> LettaResult<Tool>
pub async fn upsert(&self, request: CreateToolRequest) -> LettaResult<Tool>
Upsert a tool (create or update).
Sourcepub async fn list_mcp_servers(
&self,
) -> LettaResult<HashMap<String, McpServerConfig>>
pub async fn list_mcp_servers( &self, ) -> LettaResult<HashMap<String, McpServerConfig>>
Get a list of all configured MCP servers.
§Errors
Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.
Sourcepub async fn list_mcp_servers_with_user(
&self,
user_id: &str,
) -> LettaResult<HashMap<String, McpServerConfig>>
pub async fn list_mcp_servers_with_user( &self, user_id: &str, ) -> LettaResult<HashMap<String, McpServerConfig>>
Get a list of all configured MCP servers with optional user context.
§Arguments
user_id- Optional user ID (sent as user-id query parameter)
§Errors
Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.
Sourcepub async fn add_mcp_server(
&self,
config: McpServerConfig,
) -> LettaResult<Vec<McpServerConfig>>
pub async fn add_mcp_server( &self, config: McpServerConfig, ) -> LettaResult<Vec<McpServerConfig>>
Add a new MCP server to the Letta MCP server config.
§Arguments
config- The MCP server configuration
§Returns
Returns a list of MCP server configurations.
§Errors
Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.
Sourcepub async fn list_mcp_tools_by_server(
&self,
server_name: &str,
) -> LettaResult<Vec<McpTool>>
pub async fn list_mcp_tools_by_server( &self, server_name: &str, ) -> LettaResult<Vec<McpTool>>
Get a list of tools for a specific MCP server.
§Arguments
server_name- The name of the MCP server
§Errors
Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.
Sourcepub async fn add_mcp_tool(
&self,
server_name: &str,
tool_name: &str,
) -> LettaResult<Tool>
pub async fn add_mcp_tool( &self, server_name: &str, tool_name: &str, ) -> LettaResult<Tool>
Add an MCP tool to Letta from a specific MCP server.
§Arguments
server_name- The name of the MCP servertool_name- The name of the MCP tool
§Errors
Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.
Sourcepub async fn delete_mcp_server(&self, server_name: &str) -> LettaResult<()>
pub async fn delete_mcp_server(&self, server_name: &str) -> LettaResult<()>
Delete an MCP server.
§Arguments
server_name- The name of the MCP server to delete
§Errors
Returns a crate::error::LettaError if the request fails.
Sourcepub async fn update_mcp_server(
&self,
server_name: &str,
request: UpdateMcpServerRequest,
) -> LettaResult<McpServerConfig>
pub async fn update_mcp_server( &self, server_name: &str, request: UpdateMcpServerRequest, ) -> LettaResult<McpServerConfig>
Update an MCP server configuration.
§Arguments
server_name- The name of the MCP server to updaterequest- The update request
§Errors
Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.
Sourcepub async fn test_mcp_server(
&self,
request: TestMcpServerRequest,
) -> LettaResult<Vec<McpTool>>
pub async fn test_mcp_server( &self, request: TestMcpServerRequest, ) -> LettaResult<Vec<McpTool>>
Test an MCP server connection.
§Arguments
request- The test request containing the server configuration
§Returns
Returns a list of MCP tools available on the server.
§Errors
Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.
Sourcepub async fn run_from_source(
&self,
request: RunToolFromSourceRequest,
) -> LettaResult<RunToolFromSourceResponse>
pub async fn run_from_source( &self, request: RunToolFromSourceRequest, ) -> LettaResult<RunToolFromSourceResponse>
Run a tool from source code without creating it first.
This endpoint allows you to execute a tool directly from source code without needing to create and store it first. Useful for one-off tool executions or testing.
§Arguments
request- The request containing source code and arguments
§Returns
Returns the tool execution result including output, status, and any stdout/stderr.
§Errors
Returns a crate::error::LettaError if:
- The source code has validation errors
- The tool execution fails
- The request fails or response cannot be parsed
§Example
let request = RunToolFromSourceRequest {
source_code: r#"
def add_numbers(a: float, b: float) -> float:
"""Add two numbers.
Args:
a: First number
b: Second number
Returns:
float: Sum of the numbers
"""
return a + b
"#.to_string(),
args: json!({ "a": 5, "b": 3 }),
source_type: Some(SourceType::Python),
..Default::default()
};
let result = client.tools().run_from_source(request).await?;
assert_eq!(result.tool_return, "8");Sourcepub async fn list_composio_apps(&self) -> LettaResult<Vec<AppModel>>
pub async fn list_composio_apps(&self) -> LettaResult<Vec<AppModel>>
List all available Composio apps.
Returns a list of all Composio applications that can be integrated with Letta. Each app provides a set of actions that can be converted into Letta tools.
§Errors
Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.
Sourcepub async fn list_composio_actions(
&self,
app_name: &str,
) -> LettaResult<Vec<ActionModel>>
pub async fn list_composio_actions( &self, app_name: &str, ) -> LettaResult<Vec<ActionModel>>
List all actions for a specific Composio app.
§Arguments
app_name- The name of the Composio app to get actions for
§Returns
Returns a list of actions available for the specified Composio app. Each action can be converted into a Letta tool.
§Errors
Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.
Sourcepub async fn add_composio_tool(&self, action_name: &str) -> LettaResult<Tool>
pub async fn add_composio_tool(&self, action_name: &str) -> LettaResult<Tool>
Add a Composio action as a Letta tool.
Converts a Composio action into a Letta tool that can be attached to agents and executed.
§Arguments
action_name- The name of the Composio action to add as a tool
§Returns
Returns the created Tool object.
§Errors
Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.
Sourcepub async fn upsert_base_tools(&self) -> LettaResult<Vec<Tool>>
pub async fn upsert_base_tools(&self) -> LettaResult<Vec<Tool>>
Upsert base tools.
Adds or updates the default set of base tools in the Letta system. This is typically used during initial setup or to refresh the base tool set.
§Returns
Returns a list of all base tools that were added or updated.
§Errors
Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.
Sourcepub fn paginated(
&self,
params: Option<PaginationParams>,
) -> PaginatedStream<Tool>
pub fn paginated( &self, params: Option<PaginationParams>, ) -> PaginatedStream<Tool>
Get a paginated stream of tools.
This method returns a PaginatedStream that automatically handles pagination
and allows streaming through all tools using async iteration.
§Arguments
params- Optional pagination parameters
§Example
let client = LettaClient::new(ClientConfig::new("http://localhost:8283")?)?;
let mut stream = client.tools().paginated(None);
while let Some(tool) = stream.next().await {
let tool = tool?;
println!("Tool: {} - {}", tool.name, tool.description.as_deref().unwrap_or(""));
}