Add comments to the MCP example (#2507)
This commit is contained in:
@@ -2,22 +2,33 @@ from pprint import pprint
|
||||
|
||||
from letta_client import Letta
|
||||
|
||||
# Connect to Letta server
|
||||
client = Letta(base_url="http://localhost:8283")
|
||||
|
||||
# Use the "everything" mcp server:
|
||||
# https://github.com/modelcontextprotocol/servers/tree/main/src/everything
|
||||
mcp_server_name = "everything"
|
||||
mcp_tool_name = "echo"
|
||||
|
||||
# List all McpTool belonging to the "everything" mcp server.
|
||||
mcp_tools = client.tools.list_mcp_tools_by_server(
|
||||
mcp_server_name=mcp_server_name,
|
||||
)
|
||||
|
||||
# We can see that "echo" is one of the tools, but it's not
|
||||
# a letta tool that can be added to a client (it has no tool id).
|
||||
for tool in mcp_tools:
|
||||
pprint(tool)
|
||||
|
||||
# Create a Tool (with a tool id) using the server and tool names.
|
||||
mcp_tool = client.tools.add_mcp_tool(
|
||||
mcp_server_name=mcp_server_name,
|
||||
mcp_tool_name=mcp_tool_name
|
||||
)
|
||||
|
||||
# Create an agent with the tool, using tool.id -- note that
|
||||
# this is the ONLY tool in the agent, you typically want to
|
||||
# also include the default tools.
|
||||
agent = client.agents.create(
|
||||
memory_blocks=[
|
||||
{
|
||||
@@ -31,6 +42,7 @@ agent = client.agents.create(
|
||||
)
|
||||
print(f"Created agent id {agent.id}")
|
||||
|
||||
# Ask the agent to call the tool.
|
||||
response = client.agents.messages.create(
|
||||
agent_id=agent.id,
|
||||
messages=[
|
||||
|
||||
Reference in New Issue
Block a user