Skip to main content
Glama

agentbay_agent_memory_query

Query agent memory across projects to retrieve patterns, decisions, and insights. Access your own memory or read another agent's memory if permitted, using tags, search, and type filters.

Instructions

Query your own agent memory, or read another agent's memory (if they granted you access). Agent memory persists across all projects.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeNo
tagsNo
searchNoSearch query
sourceNo
limitNo
targetAgentIdNoQuery another agent's memory (requires read permission)

Implementation Reference

  • src/index.ts:417-453 (registration)
    Tool registration of 'agentbay_agent_memory_query' via server.tool() with name, description, Zod schema for inputs, and async handler function.
    // Tool 19: Agent Memory Query
    server.tool(
      'agentbay_agent_memory_query',
      'Query your own agent memory, or read another agent\'s memory (if they granted you access). Agent memory persists across all projects.',
      {
        type: z.enum(['PATTERN', 'PITFALL', 'ARCHITECTURE', 'DEPENDENCY', 'TEST_INSIGHT', 'PERFORMANCE', 'DECISION', 'CONTEXT']).optional(),
        tags: z.array(z.string()).optional(),
        search: z.string().optional().describe('Search query'),
        source: z.string().optional(),
        limit: z.number().min(1).max(100).optional(),
        targetAgentId: z.string().optional().describe('Query another agent\'s memory (requires read permission)'),
      },
      async ({ type, tags, search, source, limit, targetAgentId }) => {
        let agentId = targetAgentId;
        if (!agentId) {
          const meData = await apiGet('/api/v1/me');
          agentId = meData.agentId;
          if (!agentId) return { content: [{ type: 'text' as const, text: 'Error: No agent linked to this API key. Use agentbay_agent_register first.' }] };
        }
    
        const params = new URLSearchParams();
        if (type) params.set('type', type);
        if (tags?.length) params.set('tags', tags.join(','));
        if (search) params.set('search', search);
        if (source) params.set('source', source);
        if (limit) params.set('limit', String(limit));
    
        const data = await apiGet(`/api/v1/agents/${agentId}/memory?${params.toString()}`);
        if (data.error) return { content: [{ type: 'text' as const, text: `Error: ${data.error}` }] };
        const entries = data.entries || data.memories || [];
        if (!entries.length) return { content: [{ type: 'text' as const, text: 'No agent memory entries found. Note: agent_memory_query browses by type/tags. Use "search" parameter for text search.' }] };
        const text = entries.map((k: any) =>
          `### ${k.title} (${k.type})\nID: ${k.id}\n${k.content}\n_Source: ${k.source || 'unknown'} | Confidence: ${k.confidence} | Tags: ${k.tags?.join(', ') || 'none'}_`
        ).join('\n\n');
        return { content: [{ type: 'text' as const, text: `Agent memory (${entries.length}):\n\n${text}` }] };
      }
    );
  • Input schema (Zod) for agent_memory_query: optional type, tags, search, source, limit, and targetAgentId parameters.
    {
      type: z.enum(['PATTERN', 'PITFALL', 'ARCHITECTURE', 'DEPENDENCY', 'TEST_INSIGHT', 'PERFORMANCE', 'DECISION', 'CONTEXT']).optional(),
      tags: z.array(z.string()).optional(),
      search: z.string().optional().describe('Search query'),
      source: z.string().optional(),
      limit: z.number().min(1).max(100).optional(),
      targetAgentId: z.string().optional().describe('Query another agent\'s memory (requires read permission)'),
    },
  • Handler function: resolves agent ID (from targetAgentId or /api/v1/me), builds query params, calls GET /api/v1/agents/{agentId}/memory, formats and returns results.
      async ({ type, tags, search, source, limit, targetAgentId }) => {
        let agentId = targetAgentId;
        if (!agentId) {
          const meData = await apiGet('/api/v1/me');
          agentId = meData.agentId;
          if (!agentId) return { content: [{ type: 'text' as const, text: 'Error: No agent linked to this API key. Use agentbay_agent_register first.' }] };
        }
    
        const params = new URLSearchParams();
        if (type) params.set('type', type);
        if (tags?.length) params.set('tags', tags.join(','));
        if (search) params.set('search', search);
        if (source) params.set('source', source);
        if (limit) params.set('limit', String(limit));
    
        const data = await apiGet(`/api/v1/agents/${agentId}/memory?${params.toString()}`);
        if (data.error) return { content: [{ type: 'text' as const, text: `Error: ${data.error}` }] };
        const entries = data.entries || data.memories || [];
        if (!entries.length) return { content: [{ type: 'text' as const, text: 'No agent memory entries found. Note: agent_memory_query browses by type/tags. Use "search" parameter for text search.' }] };
        const text = entries.map((k: any) =>
          `### ${k.title} (${k.type})\nID: ${k.id}\n${k.content}\n_Source: ${k.source || 'unknown'} | Confidence: ${k.confidence} | Tags: ${k.tags?.join(', ') || 'none'}_`
        ).join('\n\n');
        return { content: [{ type: 'text' as const, text: `Agent memory (${entries.length}):\n\n${text}` }] };
      }
    );
  • API helper functions (apiGet, apiPost, apiPatch, apiDelete) used by the handler to make HTTP requests to the AgentBay backend.
    async function apiGet(path: string) {
      const res = await fetch(`${API_BASE}${path}`, { headers: getHeaders() });
      return res.json();
    }
    
    async function apiPost(path: string, body: unknown) {
      const res = await fetch(`${API_BASE}${path}`, {
        method: 'POST',
        headers: getHeaders(),
        body: JSON.stringify(body),
      });
      return res.json();
    }
    
    async function apiPatch(path: string, body: unknown) {
      const res = await fetch(`${API_BASE}${path}`, {
        method: 'PATCH',
        headers: getHeaders(),
        body: JSON.stringify(body),
      });
      return res.json();
    }
    
    async function apiDelete(path: string, body?: unknown) {
      const res = await fetch(`${API_BASE}${path}`, {
        method: 'DELETE',
        headers: getHeaders(),
        ...(body ? { body: JSON.stringify(body) } : {}),
      });
      return res.json();
    }
  • getHeaders() helper that provides auth and content-type headers used by all API calls including agent_memory_query.
    function getHeaders() {
      return {
        'Authorization': `Bearer ${API_KEY}`,
        'Content-Type': 'application/json',
        'X-Agent-Framework': 'mcp-server',
      };
    }
Behavior2/5

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

No annotations provided, so the description must disclose behavioral traits. It states it queries memory and implies read-only, but doesn't explicitly say it's non-destructive, require authentication, or anything about side effects. Minimal disclosure.

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?

The description is very concise at two sentences, but lacks structure or additional details. It is efficient but could benefit from a more informative layout without being verbose.

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

Completeness2/5

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

No output schema and many parameters with poor documentation. The description fails to explain return format, parameter usage, error conditions, or how to specify target agent ID. Incomplete for effective use.

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

Parameters2/5

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

Schema coverage is low (33%) with only search and targetAgentId described. The description does not explain the other parameters (type, tags, source, limit). It adds no parameter-level meaning beyond the overall operation.

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 queries agent memory, both own and others' with permission, and mentions persistence across projects. It distinguishes from siblings like record or grant operations but doesn't explicitly contrast with other query tools like agentbay_memory_recall.

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?

No explicit guidance on when to use this tool over alternatives. It mentions permission for querying others' memory but doesn't specify when to use other query or memory tools. Usage context is implied but not clearly bounded.

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/thomasjumper/agentbay-mcp'

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