Skip to main content
Glama

get_episodes

Retrieve recent memory episodes from a specific group to access historical data and track activity patterns for analysis.

Instructions

Get the most recent memory episodes for a specific group.

Args:
    group_id: ID of the group to retrieve episodes from. If not provided, uses the default group_id.
    last_n: Number of most recent episodes to retrieve (default: 10)

Returns:
    List of episode dictionaries

Example:
    get_episodes(group_id="knowledge-smith", last_n=5)

@REQ: REQ-graphiti-chunk-mcp
@BP: BP-graphiti-chunk-mcp
@TASK: TASK-007-MCPTools

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
group_idNo
last_nNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool registration and handler for 'get_episodes'. Decorated with @mcp.tool() and delegates implementation to graphiti_tools.get_episodes_impl.
    @mcp.tool()
    async def get_episodes(
        group_id: Optional[str] = None,
        last_n: int = 10,
    ) -> List[Dict[str, Any]]:
        """
        Get the most recent memory episodes for a specific group.
    
        Args:
            group_id: ID of the group to retrieve episodes from. If not provided, uses the default group_id.
            last_n: Number of most recent episodes to retrieve (default: 10)
    
        Returns:
            List of episode dictionaries
    
        Example:
            get_episodes(group_id="knowledge-smith", last_n=5)
    
        @REQ: REQ-graphiti-chunk-mcp
        @BP: BP-graphiti-chunk-mcp
        @TASK: TASK-007-MCPTools
        """
        return await graphiti_tools.get_episodes_impl(
            group_id=group_id,
            last_n=last_n,
        )
  • Core handler implementation for get_episodes. Creates GraphitiClient, calls client.get_episodes, handles errors.
    async def get_episodes_impl(
        group_id: Optional[str] = None,
        last_n: int = 10,
    ) -> List[Dict[str, Any]]:
        """
        Get the most recent memory episodes for a specific group.
    
        @REQ: REQ-graphiti-chunk-mcp
        @BP: BP-graphiti-chunk-mcp
        @TASK: TASK-007-MCPTools
    
        Args:
            group_id: ID of the group to retrieve episodes from. If not provided, uses the default group_id.
            last_n: Number of most recent episodes to retrieve (default: 10)
    
        Returns:
            List of episode dictionaries
    
        Raises:
            ToolError: If retrieval operation fails
        """
        try:
            client = get_graphiti_client()
            async with client:
                group_ids = [group_id] if group_id else None
                results = await client.get_episodes(
                    last_n=last_n,
                    group_ids=group_ids,
                )
                return results
    
        except Exception as e:
            raise ToolError(
                "GET_EPISODES_ERROR",
                f"Failed to retrieve episodes: {str(e)}"
            ) from e
  • Low-level helper in GraphitiClient that retrieves episodes using graphiti.retrieve_episodes and formats them into dicts.
    async def get_episodes(
        self,
        reference_time: Optional[datetime] = None,
        last_n: int = 3,
        group_ids: Optional[List[str]] = None,
        source: Optional[EpisodeType] = None,
    ) -> List[Dict[str, Any]]:
        """
        Retrieve recent episodes from Graphiti.
    
        @REQ: REQ-graphiti-chunk-mcp
        @BP: BP-graphiti-chunk-mcp
        @TASK: TASK-005-GraphitiClient
    
        Args:
            reference_time: Reference timestamp (defaults to current time)
            last_n: Number of most recent episodes to retrieve (default: 3)
            group_ids: Optional list of group IDs to filter results
            source: Optional episode type filter
    
        Returns:
            List of episode dictionaries
    
        Raises:
            RuntimeError: If retrieval fails
        """
        if reference_time is None:
            reference_time = datetime.now()
    
        try:
            logger.debug(f"Retrieving last {last_n} episodes")
    
            episodes = await self.graphiti.retrieve_episodes(
                reference_time=reference_time,
                last_n=last_n,
                group_ids=group_ids,
                source=source,
            )
    
            # Convert EpisodicNode results to dictionaries
            episode_dicts = []
            for ep in episodes:
                episode_dicts.append({
                    "uuid": ep.uuid,
                    "name": ep.name,
                    "content": ep.content,
                    "source": ep.source.value if ep.source else None,
                    "source_description": ep.source_description,
                    "group_id": ep.group_id,
                    "created_at": ep.created_at,
                    "valid_at": ep.valid_at,
                })
    
            logger.info(f"Retrieved {len(episode_dicts)} episodes")
            return episode_dicts
    
        except Exception as e:
            logger.error(f"Failed to retrieve episodes: {e}")
            raise RuntimeError(f"Failed to retrieve episodes: {e}") from e
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves 'most recent memory episodes,' implying a read-only operation, but doesn't disclose other traits like authentication needs, rate limits, error handling, or what 'memory episodes' entail. The description lacks details on behavioral aspects beyond the basic function, leaving gaps for the agent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, starting with the core purpose, followed by parameter explanations, return value, and an example. Every sentence adds value without redundancy, and the structure is logical and efficient, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no annotations, but has an output schema), the description is fairly complete. It covers the purpose, parameters, and return value, and the output schema likely handles return details, reducing the need for more in the description. However, it lacks usage guidelines and some behavioral context, which holds it back from a perfect score.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant meaning beyond the input schema, which has 0% description coverage. It explains that 'group_id' is for retrieving episodes from a specific group, with a default fallback, and 'last_n' specifies the number of most recent episodes to retrieve, including the default value. This compensates well for the schema's lack of descriptions, providing clear semantics for both parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get the most recent memory episodes for a specific group.' It specifies the verb ('Get'), resource ('memory episodes'), and scope ('for a specific group'), which is clear and specific. However, it doesn't explicitly distinguish this tool from sibling tools like 'search_memory_facts' or 'search_memory_nodes', which might also retrieve memory-related data, so it doesn't reach the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions retrieving episodes for a group but doesn't compare it to sibling tools like 'search_memory_facts' or 'search_memory_nodes', which might serve similar purposes. There's no mention of prerequisites, exclusions, or specific contexts for usage, leaving the agent with little direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/leo7nel23/KnowkedgeSmith-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server