Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahwooders committed Oct 4, 2024
2 parents 7c736fd + b154613 commit 4fdfe9b
Show file tree
Hide file tree
Showing 22 changed files with 1,068 additions and 716 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Run All pytest Tests

env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
COMPOSIO_API_KEY: ${{ secrets.COMPOSIO_API_KEY }}

on:
push:
Expand Down Expand Up @@ -32,7 +33,7 @@ jobs:
with:
python-version: "3.12"
poetry-version: "1.8.2"
install-args: "-E dev -E postgres -E milvus -E crewai-tools -E tests"
install-args: "-E dev -E postgres -E milvus -E external-tools -E tests"

- name: Initialize credentials
run: poetry run letta quickstart --backend openai
Expand Down
77 changes: 77 additions & 0 deletions examples/composio_tool_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import json
import uuid

from letta import create_client
from letta.schemas.memory import ChatMemory
from letta.schemas.tool import Tool

"""
Setup here.
"""
# Create a `LocalClient` (you can also use a `RESTClient`, see the letta_rest_client.py example)
client = create_client()

# Generate uuid for agent name for this example
namespace = uuid.NAMESPACE_DNS
agent_uuid = str(uuid.uuid5(namespace, "letta-composio-tooling-example"))

# Clear all agents
for agent_state in client.list_agents():
if agent_state.name == agent_uuid:
client.delete_agent(agent_id=agent_state.id)
print(f"Deleted agent: {agent_state.name} with ID {str(agent_state.id)}")


"""
This example show how you can add Composio tools .
First, make sure you have Composio and some of the extras downloaded.
```
poetry install --extras "external-tools"
```
then setup letta with `letta configure`.
Aditionally, this example stars a Github repo on your behalf. You will need to configure Composio in your environment.
```
composio login
composio add github
```
Last updated Oct 2, 2024. Please check `composio` documentation for any composio related issues.
"""


def main():
from composio_langchain import Action

# Add the composio tool
tool = Tool.get_composio_tool(action=Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER)

# create tool
client.add_tool(tool)

persona = f"""
My name is Letta.
I am a personal assistant that helps star repos on Github. It is my job to correctly input the owner and repo to the {tool.name} tool based on the user's request.
Don’t forget - inner monologue / inner thoughts should always be different than the contents of send_message! send_message is how you communicate with the user, whereas inner thoughts are your own personal inner thoughts.
"""

# Create an agent
agent_state = client.create_agent(name=agent_uuid, memory=ChatMemory(human="My name is Matt.", persona=persona), tools=[tool.name])
print(f"Created agent: {agent_state.name} with ID {str(agent_state.id)}")

# Send a message to the agent
send_message_response = client.user_message(agent_id=agent_state.id, message="Star a repo composio with owner composiohq on GitHub")
for message in send_message_response.messages:
response_json = json.dumps(message.model_dump(), indent=4)
print(f"{response_json}\n")

# Delete agent
client.delete_agent(agent_id=agent_state.id)
print(f"Deleted agent: {agent_state.name} with ID {str(agent_state.id)}")


if __name__ == "__main__":
main()
73 changes: 73 additions & 0 deletions examples/crewai_tool_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import json
import uuid

from letta import create_client
from letta.schemas.memory import ChatMemory
from letta.schemas.tool import Tool

"""
This example show how you can add CrewAI tools .
First, make sure you have CrewAI and some of the extras downloaded.
```
poetry install --extras "external-tools"
```
then setup letta with `letta configure`.
"""


def main():
from crewai_tools import ScrapeWebsiteTool

crewai_tool = ScrapeWebsiteTool(website_url="https://www.example.com")

example_website_scrape_tool = Tool.from_crewai(crewai_tool)
tool_name = example_website_scrape_tool.name

# Create a `LocalClient` (you can also use a `RESTClient`, see the letta_rest_client.py example)
client = create_client()

# create tool
client.add_tool(example_website_scrape_tool)

# Confirm that the tool is in
tools = client.list_tools()
assert example_website_scrape_tool.name in [t.name for t in tools]

# Generate uuid for agent name for this example
namespace = uuid.NAMESPACE_DNS
agent_uuid = str(uuid.uuid5(namespace, "letta-crewai-tooling-example"))

# Clear all agents
for agent_state in client.list_agents():
if agent_state.name == agent_uuid:
client.delete_agent(agent_id=agent_state.id)
print(f"Deleted agent: {agent_state.name} with ID {str(agent_state.id)}")

# google search persona
persona = f"""
My name is Letta.
I am a personal assistant who answers a user's questions about a website `example.com`. When a user asks me a question about `example.com`, I will use a tool called {tool_name} which will search `example.com` and answer the relevant question.
Don’t forget - inner monologue / inner thoughts should always be different than the contents of send_message! send_message is how you communicate with the user, whereas inner thoughts are your own personal inner thoughts.
"""

# Create an agent
agent_state = client.create_agent(name=agent_uuid, memory=ChatMemory(human="My name is Matt.", persona=persona), tools=[tool_name])
print(f"Created agent: {agent_state.name} with ID {str(agent_state.id)}")

# Send a message to the agent
send_message_response = client.user_message(agent_id=agent_state.id, message="What's on the example.com website?")
for message in send_message_response.messages:
response_json = json.dumps(message.model_dump(), indent=4)
print(f"{response_json}\n")

# Delete agent
client.delete_agent(agent_id=agent_state.id)
print(f"Deleted agent: {agent_state.name} with ID {str(agent_state.id)}")


if __name__ == "__main__":
main()
189 changes: 0 additions & 189 deletions examples/google_search.py

This file was deleted.

Loading

0 comments on commit 4fdfe9b

Please sign in to comment.