Back to Mastra

Reference: Agent.getInstructions() | Agents

docs/src/content/en/reference/agents/getInstructions.mdx

2025-12-181.5 KB
Original Source

Agent.getInstructions()

The .getInstructions() method retrieves the instructions configured for an agent, resolving them if they're a function. These instructions guide the agent's behavior and define its capabilities and constraints.

Usage example

typescript
await agent.getInstructions()

Parameters

<PropertiesTable content={[ { name: 'options', type: '{ requestContext?: RequestContext }', isOptional: true, defaultValue: '{}', description: 'Optional configuration object containing request context.', properties: [ { type: '{ requestContext?: RequestContext }', parameters: [ { name: 'requestContext', type: 'RequestContext', isOptional: true, defaultValue: 'undefined', description: 'Request Context for dependency injection and contextual information.', }, ], }, ], }, ]} />

Returns

<PropertiesTable content={[ { name: 'instructions', type: 'SystemMessage | Promise', description: 'The instructions configured for the agent. SystemMessage can be: string | string[] | CoreSystemMessage | CoreSystemMessage[] | SystemModelMessage | SystemModelMessage[]. Returns either directly or as a promise that resolves to the instructions.', }, ]} />

Extended usage example

typescript
await agent.getInstructions({
  requestContext: new RequestContext(),
})