Skip to content

Commit bb0a919

Browse files
marthakellyAbubakar-01claude
committed
docs(mastra): simplify AG-UI context access in Agent instructions example
Drops the inline TypeScript typecast from the Mastra agent-app-context example and uses optional chaining + direct access instead, so the doc snippet is easier to read and copy. Keeps optional chaining on `.find` so the example stays safe when the AG-UI context is absent. Also fixes the `[!code highlight:N]` count after the comment line was removed. Ports @Abubakar-01's changes from CopilotKit#4125 so they can ship together with the `requestContext` rename, targeting the new `showcase/shell-docs/` path after the shell restructure on main. Co-authored-by: Muhammad Abubakar <abubakaran102025@gmail.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bcd5a92 commit bb0a919

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

docs/content/docs/integrations/mastra/agent-app-context.mdx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,14 @@ Some examples might be: the current user, the current page, etc. This can be sha
6666
name: "Colleagues contact Agent",
6767
model: openai("gpt-4o"),
6868
// Use the injected runtime context
69-
// [!code highlight:9]
69+
// [!code highlight:8]
7070
instructions: ({ requestContext }) => {
71-
// AG-UI context is an array of items, the specific context can be grabbed by filtering
72-
const aguiContext = requestContext.get('ag-ui') as { context: Array<{ description: string; value: unknown }> } | undefined;
73-
const colleaguesContextItem = aguiContext?.context?.find((contextItem: { description: string; value: unknown }) => contextItem.description === "The current user's colleagues")
74-
return `
75-
You are a helpful assistant that can help emailing colleagues.
76-
The user's colleagues are: ${JSON.stringify(colleaguesContextItem?.value, null, 2)}
77-
`
71+
const aguiContext = requestContext.get('ag-ui')?.context;
72+
const colleaguesContextItem = aguiContext?.find(contextItem => contextItem.description === "The current user's colleagues")
73+
return `
74+
You are a helpful assistant that can help emailing colleagues.
75+
The user's colleagues are: ${JSON.stringify(colleaguesContextItem?.value, null, 2)}
76+
`
7877
},
7978
// ... Everything else used to configure your agent
8079
});

showcase/shell-docs/src/content/docs/integrations/mastra/agent-app-context.mdx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@ Some examples might be: the current user, the current page, etc. This can be sha
6565
name: "Colleagues contact Agent",
6666
model: openai("gpt-4o"),
6767
// Use the injected runtime context
68-
// [!code highlight:9]
68+
// [!code highlight:8]
6969
instructions: ({ requestContext }) => {
70-
// AG-UI context is an array of items, the specific context can be grabbed by filtering
71-
const aguiContext = requestContext.get('ag-ui') as { context: Array<{ description: string; value: unknown }> } | undefined;
72-
const colleaguesContextItem = aguiContext?.context?.find((contextItem: { description: string; value: unknown }) => contextItem.description === "The current user's colleagues")
73-
return `
74-
You are a helpful assistant that can help emailing colleagues.
75-
The user's colleagues are: ${JSON.stringify(colleaguesContextItem?.value, null, 2)}
76-
`
70+
const aguiContext = requestContext.get('ag-ui')?.context;
71+
const colleaguesContextItem = aguiContext?.find(contextItem => contextItem.description === "The current user's colleagues")
72+
return `
73+
You are a helpful assistant that can help emailing colleagues.
74+
The user's colleagues are: ${JSON.stringify(colleaguesContextItem?.value, null, 2)}
75+
`
7776
},
7877
// ... Everything else used to configure your agent
7978
});

0 commit comments

Comments
 (0)