Skip to main content
Glama

get_context

Build a token-budgeted memory context block from recent and semantically relevant past events, ready to paste into an agent's system prompt. Guide retrieval by agent ID and upcoming task.

Instructions

Get a formatted memory context block ready to inject into a system prompt.

This is the drop-in replacement for LLM-provided memory (Claude Projects,
ChatGPT memory). It combines recent events with semantically relevant past
events, fits within a token budget, and formats as plain text.

Typical usage:
    context = await get_context("support-bot", "user asking about billing")
    system_prompt = f"You are a support agent.\n\n{context}"

Args:
    agent:      Your agent identifier
    task:       What the agent is about to do (guides semantic retrieval)
    max_tokens: Token budget for the context block (default 2000)
    session_id: Current session ID to exclude from context (optional)

Returns:
    Formatted context string -- paste directly into your system prompt.
    On error: {"error": <message>, "status": <http status>}.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "agent": "<agent>",
      "task": "<task>"
    },
    "name": "get_context"
  }
}

Input Schema

NameRequiredDescriptionDefault
taskYes
agentYes
max_tokensNo
session_idNo

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.3/5.0
Behavior3/5

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

With no annotations, the description carries the full burden and does disclose meaningful behavior: it merges recency and semantic relevance, respects a token budget, returns plain text, and returns a structured error object with an HTTP status on failure. However, it never states side effects (whether calling it logs an event or mutates state) or how relevance/budget trade-offs are resolved, which matters for an unannotated tool.

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

Conciseness4/5

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

Well front-loaded: purpose sentence first, then composition, then usage example, Args, and Returns. The code sample and the Claude Projects/ChatGPT memory analogy add value, though the analogy is somewhat expendable length in an otherwise tight definition.

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

Completeness5/5

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

Complete for a 4-parameter tool with an output schema: the description covers purpose, retrieval semantics, budget behavior, all parameter meanings, and the error return shape, so an agent has everything needed to call it correctly and handle failures.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate and does: `task` is explained as guiding semantic retrieval (not just a label), `max_tokens` as the budget with its 2000 default, and `session_id` as excluding the current session from context — a non-obvious semantic an agent would otherwise get wrong.

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

Purpose5/5

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

States a specific verb and resource ('Get a formatted memory context block') and immediately explains composition: recent events combined with semantically relevant past events, token-budgeted, plain text. This distinguishes it from retrieval siblings like query_events or search_memory, which return raw results rather than an injectable prompt block.

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

Usage Guidelines4/5

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

Provides a concrete usage convention including a runnable example showing the context being interpolated into a system prompt, and frames it as a drop-in replacement for LLM-native memory. It lacks explicit exclusions (e.g., when to prefer search_memory or query_events instead), so it stops short of a 5.

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