LocalClient
LocalClient
class LocalClient(AbstractClient)
A local client for Letta, which corresponds to a single user.
Attributes:
auto_save
bool - Whether to automatically save changes.user_id
str - The user ID.debug
bool - Whether to print debug information.interface
QueuingInterface - The interface for the client.server
SyncServer - The server for the client.
__init__
def __init__(auto_save: bool = False,
user_id: Optional[str] = None,
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: Optional[str] = None,
agent_name: Optional[str] = None) -> bool
Check if an agent exists
Arguments:
agent_id
str - ID of the agentagent_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 agentembedding_config
EmbeddingConfig - Embedding configurationllm_config
LLMConfig - LLM configurationmemory
Memory - Memory configurationsystem
str - System configurationtools
List[str] - List of toolsinclude_base_tools
bool - Include base toolsmetadata
Dict - Metadatadescription
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 agentname
str - Name of the agentdescription
str - Description of the agentsystem
str - System configurationtools
List[str] - List of toolsmetadata
Dict - Metadatallm_config
LLMConfig - LLM configurationembedding_config
EmbeddingConfig - Embedding configurationmessage_ids
List[str] - List of message IDsmemory
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 agentnew_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: str) -> 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
send_message
def send_message(
message: str,
role: str,
agent_id: Optional[str] = None,
agent_name: Optional[str] = None,
stream_steps: bool = False,
stream_tokens: bool = False,
include_full_message: Optional[bool] = False) -> LettaResponse
Send a message to an agent
Arguments:
message
str - Message to sendrole
str - Role of the messageagent_id
str - ID of the agentname(str)
- Name of the senderstream
bool - Stream the response (default:False
)
Returns:
response
LettaResponse - Response from the agent
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 agentmessage
str - Message to send
Returns:
response
LettaResponse - Response from the agent
run_command
def run_command(agent_id: str, command: str) -> LettaResponse
Run a command on the agent
Arguments:
agent_id
str - The agent IDcommand
str - The command to run
Returns:
LettaResponse
- The response from the agent
create_human
def create_human(name: str, text: str)
Create a human block template (saved human string to pre-fill ChatMemory
)
Arguments:
name
str - Name of the human blocktext
str - Text of the human block
Returns:
human
Human - Human block
create_persona
def create_persona(name: str, text: str)
Create a persona block template (saved persona string to pre-fill ChatMemory
)
Arguments:
name
str - Name of the persona blocktext
str - Text of the persona block
Returns:
persona
Persona - Persona block
list_humans
def list_humans()
List available human block templates
Returns:
humans
List[Human] - List of human blocks
list_personas
def list_personas() -> List[Persona]
List available persona block templates
Returns:
personas
List[Persona] - List of persona blocks
update_human
def update_human(human_id: str, text: str)
Update a human block template
Arguments:
human_id
str - ID of the human blocktext
str - Text of the human block
Returns:
human
Human - Updated human block
update_persona
def update_persona(persona_id: str, text: str)
Update a persona block template
Arguments:
persona_id
str - ID of the persona blocktext
str - Text of the persona block
Returns:
persona
Persona - Updated persona block
get_persona
def get_persona(id: str) -> Persona
Get a persona block template
Arguments:
id
str - ID of the persona block
Returns:
persona
Persona - Persona block
get_human
def get_human(id: str) -> Human
Get a human block template
Arguments:
id
str - ID of the human block
Returns:
human
Human - Human 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
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_persona
def delete_persona(id: str)
Delete a persona block template
Arguments:
id
str - ID of the persona block
delete_human
def delete_human(id: str)
Delete a human block template
Arguments:
id
str - ID of the human block
add_tool
def add_tool(tool: Tool, update: Optional[bool] = True) -> Tool
Adds a tool directly.
Arguments:
tool
Tool - The tool to add.update
bool, optional - Update the tool if it already exists. Defaults to True.
Returns:
None
create_tool
def create_tool(func,
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 toolname
str - Name of the toolfunc
callable - Function to wrap in a tooltags
List[str] - Tags for the tool
Returns:
tool
Tool - Updated tool
list_tools
def list_tools()
List available tools for the user.
Returns:
tools
List[Tool] - List of tools
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
delete_tool
def delete_tool(id: str)
Delete a tool given the ID.
Arguments:
id
str - ID of the tool
get_tool_id
def get_tool_id(name: str) -> Optional[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)
load_data
def load_data(connector: DataConnector, source_name: str)
Load data into a source
Arguments:
connector
DataConnector - Data connectorsource_name
str - Name 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 filesource_id
str - ID of the sourceblocking
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
delete_source
def delete_source(source_id: str)
Delete a source
Arguments:
source_id
str - ID of the source
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
attach_source_to_agent
def attach_source_to_agent(agent_id: str,
source_id: Optional[str] = None,
source_name: Optional[str] = None)
Attach a source to an agent
Arguments:
agent_id
str - ID of the agentsource_id
str - ID of the sourcesource_name
str - Name of the source
detach_source_from_agent
def detach_source_from_agent(agent_id: str,
source_id: Optional[str] = None,
source_name: Optional[str] = None)
Detach a source from an agent by removing all Passage
objects that were loaded from the source from archival memory.
Arguments:
agent_id
str - ID of the agentsource_id
str - ID of the sourcesource_name
str - Name of the source
Returns:
source
Source - Detached source
list_sources
def list_sources() -> List[Source]
List available sources
Returns:
sources
List[Source] - List of sources
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 sourcename
str - Name of the source
Returns:
source
Source - Updated source
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 agentmemory
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 agentmemory_id
str - ID of the memory
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 agentbefore
str - Get memories before a certain timeafter
str - Get memories after a certain timelimit
int - Limit number of memories
Returns:
passages
List[Passage] - List of passages
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 agentbefore
str - Get messages before a certain timeafter
str - Get messages after a certain timelimit
int - Limit number of messages
Returns:
messages
List[Message] - List of messages
list_models
def list_models() -> List[LLMConfig]
List available LLM models
Returns:
models
List[LLMConfig] - List of LLM models
list_embedding_models
def list_embedding_models() -> List[EmbeddingConfig]
List available embedding models
Returns:
models
List[EmbeddingConfig] - List of embedding models
list_blocks
def list_blocks(label: Optional[str] = None,
templates_only: Optional[bool] = True) -> List[Block]
List available blocks
Arguments:
label
str - Label of the blocktemplates_only
bool - List only templates
Returns:
blocks
List[Block] - List of blocks
create_block
def create_block(name: str, text: str, label: Optional[str] = None) -> Block
Create a block
Arguments:
label
str - Label of the blockname
str - Name of the blocktext
str - Text of the block
Returns:
block
Block - Created block
update_block
def update_block(block_id: str,
name: Optional[str] = None,
text: Optional[str] = None) -> Block
Update a block
Arguments:
block_id
str - ID of the blockname
str - Name of the blocktext
str - Text of the block
Returns:
block
Block - Updated block
get_block
def get_block(block_id: str) -> Block
Get a block
Arguments:
block_id
str - ID of the block
Returns:
block
Block - Block
delete_block
def delete_block(id: str) -> Block
Delete a block
Arguments:
id
str - ID of the block
Returns:
block
Block - Deleted block