{"record":{"id":"52913da03a5b88f6","repo":"mastra-ai/mastra","slug":"agent-network-memory-required","errorCode":"AGENT_NETWORK_MEMORY_REQUIRED","errorMessage":"Memory is required for the agent network to function properly. Please configure memory for the agent.","messagePattern":"Memory is required for the agent network to function properly\\. Please configure memory for the agent\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":400,"severity":"error","filePath":"packages/core/src/loop/network/index.ts","lineNumber":2170,"sourceCode":"  /**\n   * Structured output configuration for the network's final result.\n   * When provided, generates a structured response matching the schema.\n   */\n  structuredOutput?: OUTPUT extends {} ? StructuredOutputOptions<OUTPUT> : never;\n\n  resumeData?: any;\n  autoResumeSuspendedTools?: boolean;\n  mastra?: Mastra;\n  onStepFinish?: NetworkOptions<OUTPUT>['onStepFinish'];\n  onError?: NetworkOptions<OUTPUT>['onError'];\n  onAbort?: NetworkOptions<OUTPUT>['onAbort'];\n  abortSignal?: NetworkOptions<OUTPUT>['abortSignal'];\n}): Promise<MastraAgentNetworkStream<OUTPUT>> {\n  // Validate that memory is available before starting the network\n  const memoryToUse = await routingAgent.getMemory({ requestContext });\n\n  if (!memoryToUse) {\n    throw new MastraError({\n      id: 'AGENT_NETWORK_MEMORY_REQUIRED',\n      domain: ErrorDomain.AGENT_NETWORK,\n      category: ErrorCategory.USER,\n      text: 'Memory is required for the agent network to function properly. Please configure memory for the agent.',\n      details: {\n        status: 400,\n      },\n    });\n  }\n\n  assertNetworkSupportsMemory(memoryToUse, routingAgentOptions?.memory?.options);\n\n  const task = getLastMessage(messages);\n\n  let resumeDataFromTask: any | undefined;\n  let runIdFromTask: string | undefined;\n  if (autoResumeSuspendedTools && threadId) {\n    let lastAssistantMessage: MastraDBMessage | undefined;","sourceCodeStart":2152,"sourceCodeEnd":2188,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/loop/network/index.ts#L2152-L2188","documentation":"Before starting an agent network, networkLoop validates that the routing agent can resolve a Memory instance via agent.getMemory(). Networks require memory to track threads, resources and inter-agent context, so a missing memory is a 400-class USER configuration error.","triggerScenarios":"Calling agent.network() (or the streaming entry that calls this validation) with an agent constructed without a memory option, or with a memory factory/config that resolves to undefined at runtime (e.g. getMemory override returning nothing).","commonSituations":"Creating a minimal Agent({ name, model }) for network testing without memory; a custom getMemory() override that returns undefined when storage is not configured; refactoring memory out of an agent that is still used as a network routing agent.","solutions":["Attach a Memory instance to the routing agent: new Agent({ ..., memory: new Memory({ storage }) }).","Ensure the storage backend passed to Memory is defined (configure LibSQL/Postgres/InMemory storage).","If getMemory is overridden, make sure it resolves to a Memory instance, not undefined.","Verify with agent.getMemory({ requestContext }) before calling network() that a memory resolves."],"exampleFix":"// before\nconst agent = new Agent({ name: 'router', instructions: '...', model: 'openai/gpt-4o' });\nawait agent.network('do the task');\n// after\nconst agent = new Agent({ name: 'router', instructions: '...', model: 'openai/gpt-4o', memory: new Memory({ storage: new LibSQLStore({ url: 'file:./mastra.db' }) }) });\nawait agent.network('do the task');","handlingStrategy":"validation","validationCode":"const mem = await routingAgent.getMemory({ requestContext });\nif (!mem) throw new Error('Routing agent must have memory configured before agent.network()');\nawait routingAgent.network(input);","typeGuard":"function hasMemory(a: { getMemory: (o: unknown) => Promise<unknown> }): a is Required<{ getMemory: (o: unknown) => Promise<object> }> {\n  return typeof a.getMemory === 'function';\n}\n// usage: (await agent.getMemory({})) ? proceed : configure memory","tryCatchPattern":"try {\n  await agent.network(input);\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'AGENT_NETWORK_MEMORY_REQUIRED') {\n    agent = new Agent({ ...agentConfig, memory: new Memory({ storage }) });\n    return agent.network(input);\n  }\n  throw e;\n}","preventionTips":["Always pass memory to agents used with network()","Validate getMemory() resolves before starting network loops in tests","Never rely on getMemory overrides that can return undefined"],"tags":["agent-network","memory","configuration","missing-dependency"],"backgroundTag":"missing-required-config","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}