Packages

Elixir client library for the Letta AI API, providing comprehensive access to AI agent functionality including memory management, conversation handling, and tool integration.

Current section

Files

Jump to
letta_api lib letta_api api blocks.ex
Raw

lib/letta_api/api/blocks.ex

# NOTE: This file is auto generated by OpenAPI Generator 7.13.0 (https://openapi-generator.tech).
# Do not edit this file manually.
defmodule LettaAPI.Api.Blocks do
@moduledoc """
API calls for all endpoints tagged `Blocks`.
"""
alias LettaAPI.Connection
import LettaAPI.RequestBuilder
@doc """
Count Blocks
Count all blocks created by a user.
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `opts` (keyword): Optional parameters
- `:user_id` (String.t):
### Returns
- `{:ok, integer()}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec count_blocks(Tesla.Env.client, keyword()) :: {:ok, integer()} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def count_blocks(connection, opts \\ []) do
optional_params = %{
:user_id => :headers
}
request =
%{}
|> method(:get)
|> url("/v1/blocks/count")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, false},
{422, LettaAPI.Model.HttpValidationError}
])
end
@doc """
Create Block
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `create_block` (CreateBlock):
- `opts` (keyword): Optional parameters
- `:user_id` (String.t):
### Returns
- `{:ok, LettaAPI.Model.Block.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec create_block(Tesla.Env.client, LettaAPI.Model.CreateBlock.t, keyword()) :: {:ok, LettaAPI.Model.Block.t} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def create_block(connection, create_block, opts \\ []) do
optional_params = %{
:user_id => :headers
}
request =
%{}
|> method(:post)
|> url("/v1/blocks/")
|> add_param(:body, :body, create_block)
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, LettaAPI.Model.Block},
{422, LettaAPI.Model.HttpValidationError}
])
end
@doc """
Delete Block
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `block_id` (String.t):
- `opts` (keyword): Optional parameters
- `:user_id` (String.t):
### Returns
- `{:ok, LettaAPI.Model.Block.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec delete_block(Tesla.Env.client, String.t, keyword()) :: {:ok, LettaAPI.Model.Block.t} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def delete_block(connection, block_id, opts \\ []) do
optional_params = %{
:user_id => :headers
}
request =
%{}
|> method(:delete)
|> url("/v1/blocks/#{block_id}")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, LettaAPI.Model.Block},
{422, LettaAPI.Model.HttpValidationError}
])
end
@doc """
List Agents For Block
Retrieves all agents associated with the specified block. Raises a 404 if the block does not exist.
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `block_id` (String.t):
- `opts` (keyword): Optional parameters
- `:user_id` (String.t):
### Returns
- `{:ok, [%AgentState{}, ...]}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec list_agents_for_block(Tesla.Env.client, String.t, keyword()) :: {:ok, [LettaAPI.Model.AgentState.t]} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def list_agents_for_block(connection, block_id, opts \\ []) do
optional_params = %{
:user_id => :headers
}
request =
%{}
|> method(:get)
|> url("/v1/blocks/#{block_id}/agents")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, LettaAPI.Model.AgentState},
{422, LettaAPI.Model.HttpValidationError}
])
end
@doc """
List Blocks
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `opts` (keyword): Optional parameters
- `:label` (String.t): Labels to include (e.g. human, persona)
- `:templates_only` (boolean()): Whether to include only templates
- `:name` (String.t): Name of the block
- `:identity_id` (String.t): Search agents by identifier id
- `:identifier_keys` ([String.t]): Search agents by identifier keys
- `:user_id` (String.t):
### Returns
- `{:ok, [%Block{}, ...]}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec list_blocks(Tesla.Env.client, keyword()) :: {:ok, [LettaAPI.Model.Block.t]} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def list_blocks(connection, opts \\ []) do
optional_params = %{
:label => :query,
:templates_only => :query,
:name => :query,
:identity_id => :query,
:identifier_keys => :query,
:user_id => :headers
}
request =
%{}
|> method(:get)
|> url("/v1/blocks/")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, LettaAPI.Model.Block},
{422, LettaAPI.Model.HttpValidationError}
])
end
@doc """
Modify Block
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `block_id` (String.t):
- `block_update` (BlockUpdate):
- `opts` (keyword): Optional parameters
- `:user_id` (String.t):
### Returns
- `{:ok, LettaAPI.Model.Block.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec modify_block(Tesla.Env.client, String.t, LettaAPI.Model.BlockUpdate.t, keyword()) :: {:ok, LettaAPI.Model.Block.t} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def modify_block(connection, block_id, block_update, opts \\ []) do
optional_params = %{
:user_id => :headers
}
request =
%{}
|> method(:patch)
|> url("/v1/blocks/#{block_id}")
|> add_param(:body, :body, block_update)
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, LettaAPI.Model.Block},
{422, LettaAPI.Model.HttpValidationError}
])
end
@doc """
Retrieve Block
### Parameters
- `connection` (LettaAPI.Connection): Connection to server
- `block_id` (String.t):
- `opts` (keyword): Optional parameters
- `:user_id` (String.t):
### Returns
- `{:ok, LettaAPI.Model.Block.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec retrieve_block(Tesla.Env.client, String.t, keyword()) :: {:ok, LettaAPI.Model.Block.t} | {:ok, LettaAPI.Model.HttpValidationError.t} | {:error, Tesla.Env.t}
def retrieve_block(connection, block_id, opts \\ []) do
optional_params = %{
:user_id => :headers
}
request =
%{}
|> method(:get)
|> url("/v1/blocks/#{block_id}")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, LettaAPI.Model.Block},
{422, LettaAPI.Model.HttpValidationError}
])
end
end