Files
letta-server/examples/docs/rest_client.py
cthomas 2f24a0886e chore: clean up api (#2384)
Co-authored-by: Shubham Naik <shubham.naik10@gmail.com>
Co-authored-by: Shubham Naik <shub@memgpt.ai>
Co-authored-by: Matthew Zhou <mattzh1314@gmail.com>
Co-authored-by: mlong93 <35275280+mlong93@users.noreply.github.com>
Co-authored-by: Mindy Long <mindy@letta.com>
Co-authored-by: Kevin Lin <klin5061@gmail.com>
Co-authored-by: Charles Packer <packercharles@gmail.com>
2025-01-23 21:38:11 -08:00

59 lines
1.6 KiB
Python

from letta_client import CreateBlock, Letta, MessageCreate
"""
Make sure you run the Letta server before running this example.
```
letta server
```
"""
def main():
# Connect to the server as a user
client = Letta(base_url="http://localhost:8283")
# list available configs on the server
llm_configs = client.models.list_llms()
print(f"Available LLM configs: {llm_configs}")
embedding_configs = client.models.list_embedding_models()
print(f"Available embedding configs: {embedding_configs}")
# Create an agent
agent_state = client.agents.create(
name="my_agent",
memory_blocks=[
CreateBlock(
label="human",
value="My name is Sarah",
),
CreateBlock(
label="persona",
value="I am a friendly AI",
),
],
model=llm_configs[0].handle,
embedding=embedding_configs[0].handle,
)
print(f"Created agent: {agent_state.name} with ID {str(agent_state.id)}")
# Send a message to the agent
print(f"Created agent: {agent_state.name} with ID {str(agent_state.id)}")
response = client.agents.messages.send(
agent_id=agent_state.id,
messages=[
MessageCreate(
role="user",
content="Whats my name?",
)
],
)
print(f"Received response:", response.messages)
# Delete agent
client.agents.delete(agent_id=agent_state.id)
print(f"Deleted agent: {agent_state.name} with ID {str(agent_state.id)}")
if __name__ == "__main__":
main()