Agent.getMetadata()
The .getMetadata() method retrieves the metadata configured for an agent, resolving it if it's a function. Use metadata to classify agents in clients without encoding that data in the agent ID or name.
Usage exampleDirect link to Usage example
await agent.getMetadata()
ParametersDirect link to Parameters
options?:
{ requestContext?: RequestContext }
= {}
Optional configuration object containing request context.
{ requestContext?: RequestContext }
requestContext?:
RequestContext
Request Context passed to dynamic metadata functions. Ignored when metadata is static.
ReturnsDirect link to Returns
metadata:
Record<string, unknown> | Promise<Record<string, unknown>>
The metadata configured for the agent, or `undefined` if no metadata was configured. Returns either directly or as a promise that resolves to the metadata when defined as a function.
Extended usage exampleDirect link to Extended usage example
Static metadata:
src/mastra/agents/support-agent.ts
import { Agent } from '@mastra/core/agent'
export const supportAgent = new Agent({
id: 'support-agent',
name: 'Support Agent',
instructions: 'You help customers with support requests.',
model: 'openai/gpt-5.4',
metadata: { type: 'support' },
})
const metadata = supportAgent.getMetadata()
Dynamic metadata resolved from the request context:
src/mastra/agents/support-agent.ts
import { Agent } from '@mastra/core/agent'
export const supportAgent = new Agent({
id: 'support-agent',
name: 'Support Agent',
instructions: 'You help customers with support requests.',
model: 'openai/gpt-5.4',
metadata: ({ requestContext }) => ({
type: 'support',
tenant: requestContext.get('tenant'),
}),
})
const metadata = await supportAgent.getMetadata({ requestContext })