RESTClient

class RESTClient(AbstractClient)

REST client for Letta

Attributes:

  • base_url str - Base URL of the REST API
  • headers Dict - Headers for the REST API (includes token)

__init__

def __init__(base_url: str,
             token: str,
             api_prefix: str = "v1",
             debug: bool = False)

Initializes a new instance of Client class.

Arguments:

  • auto_save bool - Whether to automatically save changes.
  • user_id str - The user ID.
  • debug bool - Whether to print debug information.

agent_exists

def agent_exists(agent_id: str) -> bool

Check if an agent exists

Arguments:

  • agent_id str - ID of the agent
  • agent_name str - Name of the agent

Returns:

  • exists bool - True if the agent exists, False otherwise

create_agent

def create_agent(name: Optional[str] = None,
                 embedding_config: Optional[EmbeddingConfig] = None,
                 llm_config: Optional[LLMConfig] = None,
                 memory: Memory = ChatMemory(
                     human=get_human_text(DEFAULT_HUMAN),
                     persona=get_persona_text(DEFAULT_PERSONA)),
                 system: Optional[str] = None,
                 tools: Optional[List[str]] = None,
                 include_base_tools: Optional[bool] = True,
                 metadata: Optional[Dict] = {
                     "human:": DEFAULT_HUMAN,
                     "persona": DEFAULT_PERSONA
                 },
                 description: Optional[str] = None) -> AgentState

Create an agent

Arguments:

  • name str - Name of the agent
  • embedding_config EmbeddingConfig - Embedding configuration
  • llm_config LLMConfig - LLM configuration
  • memory Memory - Memory configuration
  • system str - System configuration
  • tools List[str] - List of tools
  • include_base_tools bool - Include base tools
  • metadata Dict - Metadata
  • description str - Description

Returns:

  • agent_state AgentState - State of the created agent

update_agent

def update_agent(agent_id: str,
                 name: Optional[str] = None,
                 description: Optional[str] = None,
                 system: Optional[str] = None,
                 tools: Optional[List[str]] = None,
                 metadata: Optional[Dict] = None,
                 llm_config: Optional[LLMConfig] = None,
                 embedding_config: Optional[EmbeddingConfig] = None,
                 message_ids: Optional[List[str]] = None,
                 memory: Optional[Memory] = None)

Update an existing agent

Arguments:

  • agent_id str - ID of the agent
  • name str - Name of the agent
  • description str - Description of the agent
  • system str - System configuration
  • tools List[str] - List of tools
  • metadata Dict - Metadata
  • llm_config LLMConfig - LLM configuration
  • embedding_config EmbeddingConfig - Embedding configuration
  • message_ids List[str] - List of message IDs
  • memory Memory - Memory configuration

Returns:

  • agent_state AgentState - State of the updated agent

rename_agent

def rename_agent(agent_id: str, new_name: str)

Rename an agent

Arguments:

  • agent_id str - ID of the agent
  • new_name str - New name for the agent

delete_agent

def delete_agent(agent_id: str)

Delete an agent

Arguments:

  • agent_id str - ID of the agent to delete

get_agent

def get_agent(agent_id: Optional[str] = None,
              agent_name: Optional[str] = None) -> AgentState

Get an agent’s state by it’s ID.

Arguments:

  • agent_id str - ID of the agent

Returns:

  • agent_state AgentState - State representation of the agent

get_agent_id

def get_agent_id(agent_name: str) -> AgentState

Get the ID of an agent by name (names are unique per user)

Arguments:

  • agent_name str - Name of the agent

Returns:

  • agent_id str - ID of the agent

get_in_context_memory

def get_in_context_memory(agent_id: str) -> Memory

Get the in-contxt (i.e. core) memory of an agent

Arguments:

  • agent_id str - ID of the agent

Returns:

  • memory Memory - In-context memory of the agent

update_in_context_memory

def update_in_context_memory(agent_id: str, section: str,
                             value: Union[List[str], str]) -> Memory

Update the in-context memory of an agent

Arguments:

  • agent_id str - ID of the agent

Returns:

  • memory Memory - The updated in-context memory of the agent

get_archival_memory_summary

def get_archival_memory_summary(agent_id: str) -> ArchivalMemorySummary

Get a summary of the archival memory of an agent

Arguments:

  • agent_id str - ID of the agent

Returns:

  • summary ArchivalMemorySummary - Summary of the archival memory

get_recall_memory_summary

def get_recall_memory_summary(agent_id: str) -> RecallMemorySummary

Get a summary of the recall memory of an agent

Arguments:

  • agent_id str - ID of the agent

Returns:

  • summary RecallMemorySummary - Summary of the recall memory

get_in_context_messages

def get_in_context_messages(agent_id: str) -> List[Message]

Get in-context messages of an agent

Arguments:

  • agent_id str - ID of the agent

Returns:

  • messages List[Message] - List of in-context messages

user_message

def user_message(
        agent_id: str,
        message: str,
        include_full_message: Optional[bool] = False) -> LettaResponse

Send a message to an agent as a user

Arguments:

  • agent_id str - ID of the agent
  • message str - Message to send

Returns:

  • response LettaResponse - Response from the agent

get_archival_memory

def get_archival_memory(agent_id: str,
                        before: Optional[str] = None,
                        after: Optional[str] = None,
                        limit: Optional[int] = 1000) -> List[Passage]

Get archival memory from an agent with pagination.

Arguments:

  • agent_id str - ID of the agent
  • before str - Get memories before a certain time
  • after str - Get memories after a certain time
  • limit int - Limit number of memories

Returns:

  • passages List[Passage] - List of passages

insert_archival_memory

def insert_archival_memory(agent_id: str, memory: str) -> List[Passage]

Insert archival memory into an agent

Arguments:

  • agent_id str - ID of the agent
  • memory str - Memory string to insert

Returns:

  • passages List[Passage] - List of inserted passages

delete_archival_memory

def delete_archival_memory(agent_id: str, memory_id: str)

Delete archival memory from an agent

Arguments:

  • agent_id str - ID of the agent
  • memory_id str - ID of the memory

get_messages

def get_messages(agent_id: str,
                 before: Optional[str] = None,
                 after: Optional[str] = None,
                 limit: Optional[int] = 1000) -> List[Message]

Get messages from an agent with pagination.

Arguments:

  • agent_id str - ID of the agent
  • before str - Get messages before a certain time
  • after str - Get messages after a certain time
  • limit int - Limit number of messages

Returns:

  • messages List[Message] - List of messages

send_message

def send_message(
    agent_id: str,
    message: str,
    role: str,
    name: Optional[str] = None,
    stream_steps: bool = False,
    stream_tokens: bool = False,
    include_full_message: Optional[bool] = False
) -> Union[LettaResponse, Generator[LettaStreamingResponse, None, None]]

Send a message to an agent

Arguments:

  • message str - Message to send
  • role str - Role of the message
  • agent_id str - ID of the agent
  • name(str) - Name of the sender
  • stream bool - Stream the response (default: False)
  • stream_tokens bool - Stream tokens (default: False)

Returns:

  • response LettaResponse - Response from the agent

list_humans

def list_humans()

List available human block templates

Returns:

  • humans List[Human] - List of human blocks

create_human

def create_human(name: str, text: str) -> Human

Create a human block template (saved human string to pre-fill ChatMemory)

Arguments:

  • name str - Name of the human block
  • text str - Text of the human block

Returns:

  • human Human - Human block

update_human

def update_human(human_id: str,
                 name: Optional[str] = None,
                 text: Optional[str] = None) -> Human

Update a human block template

Arguments:

  • human_id str - ID of the human block
  • text str - Text of the human block

Returns:

  • human Human - Updated human block

list_personas

def list_personas()

List available persona block templates

Returns:

  • personas List[Persona] - List of persona blocks

create_persona

def create_persona(name: str, text: str) -> Persona

Create a persona block template (saved persona string to pre-fill ChatMemory)

Arguments:

  • name str - Name of the persona block
  • text str - Text of the persona block

Returns:

  • persona Persona - Persona block

update_persona

def update_persona(persona_id: str,
                   name: Optional[str] = None,
                   text: Optional[str] = None) -> Persona

Update a persona block template

Arguments:

  • persona_id str - ID of the persona block
  • text str - Text of the persona block

Returns:

  • persona Persona - Updated persona block

get_persona

def get_persona(persona_id: str) -> Persona

Get a persona block template

Arguments:

  • id str - ID of the persona block

Returns:

  • persona Persona - Persona block

get_persona_id

def get_persona_id(name: str) -> str

Get the ID of a persona block template

Arguments:

  • name str - Name of the persona block

Returns:

  • id str - ID of the persona block

delete_persona

def delete_persona(persona_id: str) -> Persona

Delete a persona block template

Arguments:

  • id str - ID of the persona block

get_human

def get_human(human_id: str) -> Human

Get a human block template

Arguments:

  • id str - ID of the human block

Returns:

  • human Human - Human block

get_human_id

def get_human_id(name: str) -> str

Get the ID of a human block template

Arguments:

  • name str - Name of the human block

Returns:

  • id str - ID of the human block

delete_human

def delete_human(human_id: str) -> Human

Delete a human block template

Arguments:

  • id str - ID of the human block

get_source

def get_source(source_id: str) -> Source

Get a source given the ID.

Arguments:

  • source_id str - ID of the source

Returns:

  • source Source - Source

get_source_id

def get_source_id(source_name: str) -> str

Get the ID of a source

Arguments:

  • source_name str - Name of the source

Returns:

  • source_id str - ID of the source

list_sources

def list_sources() -> List[Source]

List available sources

Returns:

  • sources List[Source] - List of sources

delete_source

def delete_source(source_id: str)

Delete a source

Arguments:

  • source_id str - ID of the source

load_file_into_source

def load_file_into_source(filename: str, source_id: str, blocking=True)

Load a file into a source

Arguments:

  • filename str - Name of the file
  • source_id str - ID of the source
  • blocking bool - Block until the job is complete

Returns:

  • job Job - Data loading job including job status and metadata

create_source

def create_source(name: str) -> Source

Create a source

Arguments:

  • name str - Name of the source

Returns:

  • source Source - Created source

list_attached_sources

def list_attached_sources(agent_id: str) -> List[Source]

List sources attached to an agent

Arguments:

  • agent_id str - ID of the agent

Returns:

  • sources List[Source] - List of sources

update_source

def update_source(source_id: str, name: Optional[str] = None) -> Source

Update a source

Arguments:

  • source_id str - ID of the source
  • name str - Name of the source

Returns:

  • source Source - Updated source

attach_source_to_agent

def attach_source_to_agent(source_id: str, agent_id: str)

Attach a source to an agent

Arguments:

  • agent_id str - ID of the agent
  • source_id str - ID of the source
  • source_name str - Name of the source

detach_source

def detach_source(source_id: str, agent_id: str)

Detach a source from an agent

list_models

def list_models()

List available LLM models

Returns:

  • models List[LLMConfig] - List of LLM models

list_embedding_models

def list_embedding_models()

List available embedding models

Returns:

  • models List[EmbeddingConfig] - List of embedding models

get_tool_id

def get_tool_id(tool_name: str)

Get the ID of a tool

Arguments:

  • name str - Name of the tool

Returns:

  • id str - ID of the tool (None if not found)

create_tool

def create_tool(func: Callable,
                name: Optional[str] = None,
                update: Optional[bool] = True,
                tags: Optional[List[str]] = None) -> Tool

Create a tool. This stores the source code of function on the server, so that the server can execute the function and generate an OpenAI JSON schemas for it when using with an agent.

Arguments:

  • func callable - The function to create a tool for.
  • name - (str): Name of the tool (must be unique per-user.)
  • tags Optional[List[str]], optional - Tags for the tool. Defaults to None.
  • update bool, optional - Update the tool if it already exists. Defaults to True.

Returns:

  • tool Tool - The created tool.

update_tool

def update_tool(id: str,
                name: Optional[str] = None,
                func: Optional[Callable] = None,
                tags: Optional[List[str]] = None) -> Tool

Update a tool with provided parameters (name, func, tags)

Arguments:

  • id str - ID of the tool
  • name str - Name of the tool
  • func callable - Function to wrap in a tool
  • tags List[str] - Tags for the tool

Returns:

  • tool Tool - Updated tool

list_tools

def list_tools() -> List[Tool]

List available tools for the user.

Returns:

  • tools List[Tool] - List of tools

delete_tool

def delete_tool(name: str)

Delete a tool given the ID.

Arguments:

  • id str - ID of the tool

get_tool

def get_tool(id: str) -> Optional[Tool]

Get a tool give its ID.

Arguments:

  • id str - ID of the tool

Returns:

  • tool Tool - Tool

get_tool_id

def get_tool_id(name: str) -> Optional[str]

Get a tool ID by its name.

Arguments:

  • id str - ID of the tool

Returns:

  • tool Tool - Tool