Skip to main content

ToolApi

Struct ToolApi 

Source
pub struct ToolApi<'a> { /* private fields */ }
Expand description

Tool API operations.

Implementations§

Source§

impl<'a> ToolApi<'a>

Source

pub fn new(client: &'a LettaClient) -> Self

Create a new tool API instance.

Source

pub async fn list( &self, params: Option<ListToolsParams>, ) -> LettaResult<Vec<Tool>>

List all tools.

Source

pub async fn create(&self, request: CreateToolRequest) -> LettaResult<Tool>

Create a new tool.

Source

pub async fn get(&self, tool_id: &LettaId) -> LettaResult<Tool>

Get a specific tool by ID.

Source

pub async fn update( &self, tool_id: &LettaId, request: UpdateToolRequest, ) -> LettaResult<Tool>

Update a tool.

Source

pub async fn delete(&self, tool_id: &LettaId) -> LettaResult<()>

Delete a tool.

Source

pub async fn count(&self) -> LettaResult<u32>

Get count of tools.

Source

pub async fn upsert(&self, request: CreateToolRequest) -> LettaResult<Tool>

Upsert a tool (create or update).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 server
  • tool_name - The name of the MCP tool
§Errors

Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.

Source

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.

Source

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 update
  • request - The update request
§Errors

Returns a crate::error::LettaError if the request fails or if the response cannot be parsed.

Source

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.

Source

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");
Source

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.

Source

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.

Source

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.

Source

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.

Source

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(""));
}

Trait Implementations§

Source§

impl<'a> Debug for ToolApi<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for ToolApi<'a>

§

impl<'a> !UnwindSafe for ToolApi<'a>

§

impl<'a> Freeze for ToolApi<'a>

§

impl<'a> Send for ToolApi<'a>

§

impl<'a> Sync for ToolApi<'a>

§

impl<'a> Unpin for ToolApi<'a>

§

impl<'a> UnsafeUnpin for ToolApi<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more