@mastra/mcp-docs-server 0.0.0-commonjs-20250414101718

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
  2. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
  3. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +161 -0
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +110 -0
  6. package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
  7. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
  11. package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
  12. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
  13. package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
  14. package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
  15. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
  16. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +26 -0
  17. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
  18. package/.docs/organized/changelogs/%40mastra%2Fmem0.md +196 -0
  19. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
  20. package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
  21. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
  22. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
  24. package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
  25. package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
  26. package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
  28. package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
  29. package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
  30. package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
  31. package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
  32. package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
  33. package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
  34. package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
  35. package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
  36. package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
  39. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
  40. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +250 -0
  41. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +250 -0
  42. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
  51. package/.docs/organized/changelogs/create-mastra.md +302 -0
  52. package/.docs/organized/changelogs/mastra.md +302 -0
  53. package/.docs/organized/code-examples/agent-network.md +282 -0
  54. package/.docs/organized/code-examples/agent.md +388 -0
  55. package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
  56. package/.docs/organized/code-examples/assistant-ui.md +37 -0
  57. package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
  58. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
  59. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
  60. package/.docs/organized/code-examples/client-side-tools.md +69 -0
  61. package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
  62. package/.docs/organized/code-examples/fireworks-r1.md +159 -0
  63. package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
  64. package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
  65. package/.docs/organized/code-examples/memory-with-context.md +167 -0
  66. package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
  67. package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
  68. package/.docs/organized/code-examples/memory-with-pg.md +224 -0
  69. package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
  70. package/.docs/organized/code-examples/quick-start.md +129 -0
  71. package/.docs/organized/code-examples/stock-price-tool.md +124 -0
  72. package/.docs/organized/code-examples/weather-agent.md +353 -0
  73. package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
  74. package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
  75. package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
  76. package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
  77. package/.docs/raw/agents/adding-tools.mdx +317 -0
  78. package/.docs/raw/agents/adding-voice.mdx +175 -0
  79. package/.docs/raw/agents/agent-memory.mdx +62 -0
  80. package/.docs/raw/agents/mcp-guide.mdx +215 -0
  81. package/.docs/raw/agents/overview.mdx +303 -0
  82. package/.docs/raw/community/discord.mdx +12 -0
  83. package/.docs/raw/community/licensing.mdx +63 -0
  84. package/.docs/raw/deployment/client.mdx +120 -0
  85. package/.docs/raw/deployment/deployment.mdx +127 -0
  86. package/.docs/raw/deployment/server.mdx +282 -0
  87. package/.docs/raw/evals/custom-eval.mdx +22 -0
  88. package/.docs/raw/evals/overview.mdx +95 -0
  89. package/.docs/raw/evals/running-in-ci.mdx +81 -0
  90. package/.docs/raw/evals/textual-evals.mdx +54 -0
  91. package/.docs/raw/faq/index.mdx +63 -0
  92. package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
  93. package/.docs/raw/frameworks/next-js.mdx +238 -0
  94. package/.docs/raw/getting-started/installation.mdx +442 -0
  95. package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
  96. package/.docs/raw/getting-started/project-structure.mdx +80 -0
  97. package/.docs/raw/index.mdx +22 -0
  98. package/.docs/raw/integrations/index.mdx +213 -0
  99. package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
  100. package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
  101. package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
  102. package/.docs/raw/memory/memory-processors.mdx +131 -0
  103. package/.docs/raw/memory/overview.mdx +119 -0
  104. package/.docs/raw/memory/semantic-recall.mdx +122 -0
  105. package/.docs/raw/memory/working-memory.mdx +87 -0
  106. package/.docs/raw/observability/logging.mdx +38 -0
  107. package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
  108. package/.docs/raw/observability/tracing.mdx +115 -0
  109. package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
  110. package/.docs/raw/rag/overview.mdx +85 -0
  111. package/.docs/raw/rag/retrieval.mdx +365 -0
  112. package/.docs/raw/rag/vector-databases.mdx +340 -0
  113. package/.docs/raw/reference/agents/createTool.mdx +229 -0
  114. package/.docs/raw/reference/agents/generate.mdx +334 -0
  115. package/.docs/raw/reference/agents/getAgent.mdx +54 -0
  116. package/.docs/raw/reference/agents/stream.mdx +369 -0
  117. package/.docs/raw/reference/cli/build.mdx +55 -0
  118. package/.docs/raw/reference/cli/dev.mdx +134 -0
  119. package/.docs/raw/reference/cli/init.mdx +43 -0
  120. package/.docs/raw/reference/client-js/agents.mdx +107 -0
  121. package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
  122. package/.docs/raw/reference/client-js/logs.mdx +24 -0
  123. package/.docs/raw/reference/client-js/memory.mdx +97 -0
  124. package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
  125. package/.docs/raw/reference/client-js/tools.mdx +44 -0
  126. package/.docs/raw/reference/client-js/vectors.mdx +79 -0
  127. package/.docs/raw/reference/client-js/workflows.mdx +136 -0
  128. package/.docs/raw/reference/core/mastra-class.mdx +232 -0
  129. package/.docs/raw/reference/deployer/cloudflare.mdx +207 -0
  130. package/.docs/raw/reference/deployer/deployer.mdx +159 -0
  131. package/.docs/raw/reference/deployer/netlify.mdx +109 -0
  132. package/.docs/raw/reference/deployer/vercel.mdx +117 -0
  133. package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
  134. package/.docs/raw/reference/evals/bias.mdx +186 -0
  135. package/.docs/raw/reference/evals/completeness.mdx +174 -0
  136. package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
  137. package/.docs/raw/reference/evals/context-position.mdx +190 -0
  138. package/.docs/raw/reference/evals/context-precision.mdx +189 -0
  139. package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
  140. package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
  141. package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
  142. package/.docs/raw/reference/evals/hallucination.mdx +219 -0
  143. package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
  144. package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
  145. package/.docs/raw/reference/evals/summarization.mdx +205 -0
  146. package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
  147. package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
  148. package/.docs/raw/reference/evals/toxicity.mdx +165 -0
  149. package/.docs/raw/reference/index.mdx +12 -0
  150. package/.docs/raw/reference/memory/Memory.mdx +212 -0
  151. package/.docs/raw/reference/memory/createThread.mdx +95 -0
  152. package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
  153. package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
  154. package/.docs/raw/reference/memory/query.mdx +167 -0
  155. package/.docs/raw/reference/networks/agent-network.mdx +159 -0
  156. package/.docs/raw/reference/observability/create-logger.mdx +106 -0
  157. package/.docs/raw/reference/observability/logger.mdx +55 -0
  158. package/.docs/raw/reference/observability/otel-config.mdx +120 -0
  159. package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
  160. package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
  161. package/.docs/raw/reference/observability/providers/index.mdx +16 -0
  162. package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
  163. package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
  164. package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
  165. package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
  166. package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
  167. package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
  168. package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
  169. package/.docs/raw/reference/rag/astra.mdx +258 -0
  170. package/.docs/raw/reference/rag/chroma.mdx +281 -0
  171. package/.docs/raw/reference/rag/chunk.mdx +235 -0
  172. package/.docs/raw/reference/rag/document.mdx +127 -0
  173. package/.docs/raw/reference/rag/embeddings.mdx +160 -0
  174. package/.docs/raw/reference/rag/extract-params.mdx +226 -0
  175. package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
  176. package/.docs/raw/reference/rag/libsql.mdx +357 -0
  177. package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
  178. package/.docs/raw/reference/rag/pg.mdx +477 -0
  179. package/.docs/raw/reference/rag/pinecone.mdx +281 -0
  180. package/.docs/raw/reference/rag/qdrant.mdx +236 -0
  181. package/.docs/raw/reference/rag/rerank.mdx +212 -0
  182. package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
  183. package/.docs/raw/reference/rag/upstash.mdx +247 -0
  184. package/.docs/raw/reference/rag/vectorize.mdx +298 -0
  185. package/.docs/raw/reference/storage/libsql.mdx +74 -0
  186. package/.docs/raw/reference/storage/postgresql.mdx +48 -0
  187. package/.docs/raw/reference/storage/upstash.mdx +86 -0
  188. package/.docs/raw/reference/tools/client.mdx +207 -0
  189. package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
  190. package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
  191. package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
  192. package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
  193. package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
  194. package/.docs/raw/reference/voice/deepgram.mdx +164 -0
  195. package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
  196. package/.docs/raw/reference/voice/google.mdx +198 -0
  197. package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
  198. package/.docs/raw/reference/voice/murf.mdx +251 -0
  199. package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
  200. package/.docs/raw/reference/voice/openai.mdx +168 -0
  201. package/.docs/raw/reference/voice/playai.mdx +159 -0
  202. package/.docs/raw/reference/voice/sarvam.mdx +260 -0
  203. package/.docs/raw/reference/voice/speechify.mdx +145 -0
  204. package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
  205. package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
  206. package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
  207. package/.docs/raw/reference/voice/voice.on.mdx +189 -0
  208. package/.docs/raw/reference/voice/voice.send.mdx +118 -0
  209. package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
  210. package/.docs/raw/reference/workflows/after.mdx +88 -0
  211. package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
  212. package/.docs/raw/reference/workflows/commit.mdx +37 -0
  213. package/.docs/raw/reference/workflows/createRun.mdx +77 -0
  214. package/.docs/raw/reference/workflows/else.mdx +72 -0
  215. package/.docs/raw/reference/workflows/events.mdx +305 -0
  216. package/.docs/raw/reference/workflows/execute.mdx +110 -0
  217. package/.docs/raw/reference/workflows/if.mdx +107 -0
  218. package/.docs/raw/reference/workflows/resume.mdx +155 -0
  219. package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
  220. package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
  221. package/.docs/raw/reference/workflows/start.mdx +84 -0
  222. package/.docs/raw/reference/workflows/step-class.mdx +100 -0
  223. package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
  224. package/.docs/raw/reference/workflows/step-function.mdx +92 -0
  225. package/.docs/raw/reference/workflows/step-options.mdx +69 -0
  226. package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
  227. package/.docs/raw/reference/workflows/suspend.mdx +70 -0
  228. package/.docs/raw/reference/workflows/then.mdx +74 -0
  229. package/.docs/raw/reference/workflows/until.mdx +165 -0
  230. package/.docs/raw/reference/workflows/watch.mdx +118 -0
  231. package/.docs/raw/reference/workflows/while.mdx +168 -0
  232. package/.docs/raw/reference/workflows/workflow.mdx +233 -0
  233. package/.docs/raw/storage/overview.mdx +378 -0
  234. package/.docs/raw/voice/overview.mdx +135 -0
  235. package/.docs/raw/voice/speech-to-text.mdx +45 -0
  236. package/.docs/raw/voice/text-to-speech.mdx +52 -0
  237. package/.docs/raw/voice/voice-to-voice.mdx +310 -0
  238. package/.docs/raw/workflows/control-flow.mdx +778 -0
  239. package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
  240. package/.docs/raw/workflows/error-handling.mdx +183 -0
  241. package/.docs/raw/workflows/nested-workflows.mdx +352 -0
  242. package/.docs/raw/workflows/overview.mdx +203 -0
  243. package/.docs/raw/workflows/steps.mdx +108 -0
  244. package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
  245. package/.docs/raw/workflows/variables.mdx +313 -0
  246. package/LICENSE.md +46 -0
  247. package/README.md +129 -0
  248. package/dist/_tsup-dts-rollup.d.ts +149 -0
  249. package/dist/chunk-QWYMT5LP.js +194 -0
  250. package/dist/prepare-docs/prepare.d.ts +1 -0
  251. package/dist/prepare-docs/prepare.js +1 -0
  252. package/dist/stdio.d.ts +1 -0
  253. package/dist/stdio.js +518 -0
  254. package/package.json +60 -0
@@ -0,0 +1,282 @@
1
+ ### package.json
2
+ ```json
3
+ {
4
+ "name": "examples-agent-network",
5
+ "type": "module",
6
+ "private": true,
7
+ "description": "",
8
+ "main": "index.js",
9
+ "version": "0.0.1",
10
+ "scripts": {
11
+ "start": "npx bun src/index.ts"
12
+ },
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "@ai-sdk/openai": "^1.2.5",
18
+ "@mastra/client-js": "workspace:*",
19
+ "@mastra/core": "workspace:*",
20
+ "zod": "^3.24.2"
21
+ }
22
+ }
23
+
24
+ ```
25
+
26
+ ### agent-workflow.ts
27
+ ```typescript
28
+ import { mastra } from './mastra';
29
+
30
+ async function main() {
31
+ const wflow = mastra.getWorkflow('agentWorkflow');
32
+
33
+ const { runId, start } = wflow.createRun();
34
+
35
+ const result = await start({
36
+ triggerData: {
37
+ prompt: 'What is the capital of France?',
38
+ },
39
+ });
40
+
41
+ console.log(JSON.stringify(result, null, 2));
42
+ }
43
+
44
+ main().catch(console.error);
45
+
46
+ ```
47
+
48
+ ### index.ts
49
+ ```typescript
50
+ import { mastra } from './mastra';
51
+
52
+ async function main() {
53
+ const researchNetwork = mastra.getNetwork('Research_Network');
54
+
55
+ if (!researchNetwork) {
56
+ throw new Error('Research network not found');
57
+ }
58
+
59
+ console.log('šŸ” Starting research on Napoleon Bonaparte...\n');
60
+
61
+ // Generate a report using the research network
62
+ // Using the generate() method as per the API update (MEMORY[8bf54da9-89a8-4e5b-b875-234a1aa8a53b])
63
+ const result = await researchNetwork.stream('Give me a report on Napoleon Bonaparte', {
64
+ maxSteps: 20, // Allow enough steps for the LLM router to determine the best agents to use
65
+ });
66
+
67
+ for await (const part of result.fullStream) {
68
+ switch (part.type) {
69
+ case 'error':
70
+ console.error(part.error);
71
+ break;
72
+ case 'text-delta':
73
+ process.stdout.write(part.textDelta);
74
+ break;
75
+ case 'tool-call':
76
+ console.log(`calling tool ${part.toolName} with args ${JSON.stringify(part.args, null, 2)}`);
77
+ break;
78
+ case 'tool-result':
79
+ console.log(`tool result ${JSON.stringify(part.result, null, 2)}`);
80
+ break;
81
+ }
82
+ }
83
+
84
+ // Display the final result
85
+ console.log('\n\nšŸ“ Final Research Report:\n');
86
+
87
+ console.log('\n\nšŸ“Š Agent Interaction Summary:');
88
+ console.log(researchNetwork.getAgentInteractionSummary());
89
+
90
+ console.log('\nšŸ Research complete!');
91
+ }
92
+
93
+ // Run the main function with error handling
94
+ main().catch(error => {
95
+ console.error('āŒ Error:', error);
96
+ process.exit(1);
97
+ });
98
+
99
+ ```
100
+
101
+ ### mastra/agents/index.ts
102
+ ```typescript
103
+ import { openai } from '@ai-sdk/openai';
104
+ import { Agent } from '@mastra/core/agent';
105
+
106
+ export const primaryResearchAgent = new Agent({
107
+ name: 'Primary Research Agent',
108
+ instructions: `
109
+ You are the primary research coordinator. Your job is to:
110
+ 1. Analyze user queries to determine what type of research is needed
111
+ 2. Break down complex research questions into manageable sub-questions
112
+ 3. Synthesize information from specialized research agents into a coherent response
113
+ 4. Ensure all claims are properly supported by evidence
114
+ 5. Identify any gaps in the research that need further investigation
115
+
116
+ You should maintain a neutral, objective tone and prioritize accuracy over speed.
117
+ `,
118
+ model: openai('gpt-4o'),
119
+ });
120
+
121
+ export const webSearchAgent = new Agent({
122
+ name: 'Web Search Agent',
123
+ instructions: `
124
+ You are a web search specialist. Your job is to:
125
+ 1. Find the most relevant and up-to-date information online for a given query
126
+ 2. Evaluate the credibility of sources and prioritize reliable information
127
+ 3. Extract key facts and data points from web content
128
+ 4. Provide direct quotes and citations when appropriate
129
+ 5. Summarize findings in a clear, concise manner
130
+
131
+ Always include source URLs when reporting information.
132
+
133
+ Use the "web_search_preview" tool to search the web for information.
134
+ `,
135
+ model: openai.responses('gpt-4o-mini'),
136
+ tools: {
137
+ web_search_preview: openai.tools.webSearchPreview(),
138
+ },
139
+ });
140
+
141
+ export const academicResearchAgent = new Agent({
142
+ name: 'Academic Research Agent',
143
+ instructions: `
144
+ You are an academic research specialist. Your job is to:
145
+ 1. Analyze topics from an academic perspective
146
+ 2. Identify key theories, frameworks, and scholarly debates relevant to a query
147
+ 3. Provide historical context and development of ideas
148
+ 4. Cite academic sources properly
149
+ 5. Explain complex academic concepts in accessible language
150
+
151
+ Prioritize peer-reviewed research and established academic sources.
152
+ `,
153
+ model: openai('gpt-4o'),
154
+ });
155
+
156
+ export const factCheckingAgent = new Agent({
157
+ name: 'Fact Checking Agent',
158
+ instructions: `
159
+ You are a fact-checking specialist. Your job is to:
160
+ 1. Verify claims made by other agents or in user queries
161
+ 2. Identify potential misinformation or unsubstantiated claims
162
+ 3. Cross-reference information across multiple reliable sources
163
+ 4. Provide corrections with supporting evidence
164
+ 5. Rate the confidence level of verified information
165
+
166
+ Be thorough and skeptical, but fair in your assessments.
167
+ `,
168
+ model: openai('gpt-4o-mini'),
169
+ });
170
+
171
+ export const dataAnalysisAgent = new Agent({
172
+ name: 'Data Analysis Agent',
173
+ instructions: `
174
+ You are a data analysis specialist. Your job is to:
175
+ 1. Interpret numerical data and statistics related to research queries
176
+ 2. Identify trends, patterns, and correlations in data
177
+ 3. Evaluate the methodology behind data collection and analysis
178
+ 4. Explain statistical concepts in accessible language
179
+ 5. Create clear summaries of data-driven findings
180
+
181
+ Always consider sample sizes, statistical significance, and potential biases in data.
182
+ `,
183
+ model: openai('gpt-4o'),
184
+ });
185
+
186
+ ```
187
+
188
+ ### mastra/index.ts
189
+ ```typescript
190
+ import { Mastra } from '@mastra/core';
191
+ import { createLogger } from '@mastra/core/logger';
192
+ import { researchNetwork } from './network';
193
+ import { webSearchAgent } from './agents';
194
+ import { agentWorkflow } from './workflows';
195
+
196
+ export const mastra = new Mastra({
197
+ agents: {
198
+ webSearchAgent,
199
+ },
200
+ networks: {
201
+ researchNetwork,
202
+ },
203
+ workflows: {
204
+ agentWorkflow,
205
+ },
206
+ logger: createLogger({ name: 'Chef', level: 'info' }),
207
+ serverMiddleware: [
208
+ {
209
+ handler: (c, next) => {
210
+ console.log('Middleware called');
211
+ return next();
212
+ },
213
+ },
214
+ ],
215
+ });
216
+
217
+ ```
218
+
219
+ ### mastra/network/index.ts
220
+ ```typescript
221
+ import { openai } from '@ai-sdk/openai';
222
+ import { AgentNetwork } from '@mastra/core/network';
223
+ import {
224
+ primaryResearchAgent,
225
+ webSearchAgent,
226
+ academicResearchAgent,
227
+ factCheckingAgent,
228
+ dataAnalysisAgent,
229
+ } from '../agents';
230
+
231
+ export const researchNetwork = new AgentNetwork({
232
+ name: 'Research Network',
233
+ agents: [primaryResearchAgent, webSearchAgent, academicResearchAgent, factCheckingAgent, dataAnalysisAgent],
234
+ model: openai('gpt-4o'), // Add the model property which is required
235
+ instructions: `
236
+ You are a research coordination system that routes queries to the appropriate specialized agents.
237
+
238
+ Your available agents are:
239
+ 1. Primary Research Agent: Coordinates research efforts, breaks down complex questions, and synthesizes information
240
+ 2. Web Search Agent: Finds up-to-date information online with proper citations
241
+ 3. Academic Research Agent: Provides academic perspectives, theories, and scholarly context
242
+ 4. Fact Checking Agent: Verifies claims and identifies potential misinformation
243
+ 5. Data Analysis Agent: Interprets numerical data, statistics, and identifies patterns
244
+
245
+ For each user query:
246
+ 1. Start with the Primary Research Agent to analyze the query and break it down
247
+ 2. Route sub-questions to the appropriate specialized agents based on their expertise
248
+ 3. Use the Fact Checking Agent to verify important claims when necessary
249
+ 4. Return to the Primary Research Agent to synthesize all findings into a comprehensive response
250
+
251
+ Always maintain a chain of evidence and proper attribution between agents.
252
+ `,
253
+ });
254
+
255
+ ```
256
+
257
+ ### mastra/workflows/index.ts
258
+ ```typescript
259
+ import { Workflow } from '@mastra/core/workflows';
260
+ import { z } from 'zod';
261
+ import { webSearchAgent } from '../agents';
262
+
263
+ export const agentWorkflow = new Workflow({
264
+ name: 'Agent Workflow',
265
+ steps: [webSearchAgent.toStep()],
266
+ triggerSchema: z.object({
267
+ prompt: z.string(),
268
+ }),
269
+ });
270
+
271
+ agentWorkflow
272
+ .step(webSearchAgent, {
273
+ variables: {
274
+ prompt: {
275
+ step: 'trigger',
276
+ path: 'prompt',
277
+ },
278
+ },
279
+ })
280
+ .commit();
281
+
282
+ ```
@@ -0,0 +1,388 @@
1
+ ### package.json
2
+ ```json
3
+ {
4
+ "name": "examples-agent",
5
+ "type": "module",
6
+ "private": true,
7
+ "description": "",
8
+ "main": "index.js",
9
+ "version": "0.0.1",
10
+ "scripts": {
11
+ "start-deployed": "npx bun src/with-deployed.ts",
12
+ "start": "npx bun src/index.ts"
13
+ },
14
+ "keywords": [],
15
+ "author": "",
16
+ "license": "MIT",
17
+ "dependencies": {
18
+ "@ai-sdk/openai": "latest",
19
+ "@mastra/core": "workspace:*",
20
+ "zod": "^3.24.2"
21
+ }
22
+ }
23
+
24
+ ```
25
+
26
+ ### index.ts
27
+ ```typescript
28
+ import { z } from 'zod';
29
+ import { mastra } from './mastra';
30
+
31
+ const agent = mastra.getAgent('chefAgent');
32
+ const responsesAgent = mastra.getAgent('chefAgentResponses');
33
+
34
+ async function text() {
35
+ // Query 1: Basic pantry ingredients
36
+ const query1 =
37
+ 'In my kitchen I have: pasta, canned tomatoes, garlic, olive oil, and some dried herbs (basil and oregano). What can I make?';
38
+ console.log(`Query 1: ${query1}`);
39
+
40
+ const pastaResponse = await agent.generate(query1);
41
+ console.log('\nšŸ‘Øā€šŸ³ Chef Michel:', pastaResponse.text);
42
+ console.log('\n-------------------\n');
43
+ }
44
+
45
+ async function generateText() {
46
+ // Query 1: Basic pantry ingredients
47
+
48
+ const query1 =
49
+ 'In my kitchen I have: pasta, canned tomatoes, garlic, olive oil, and some dried herbs (basil and oregano). What can I make?';
50
+ console.log(`Query 1: ${query1}`);
51
+
52
+ const pastaResponse = await agent.generate(query1);
53
+
54
+ console.log('\nšŸ‘Øā€šŸ³ Chef Michel:', pastaResponse.text);
55
+ console.log('\n-------------------\n');
56
+ }
57
+
58
+ async function textStream() {
59
+ // Query 2: More ingredients
60
+ const query2 =
61
+ "Now I'm over at my friend's house, and they have: chicken thighs, coconut milk, sweet potatoes, and some curry powder.";
62
+ console.log(`Query 2: ${query2}`);
63
+
64
+ const curryResponse = await agent.stream(query2);
65
+
66
+ console.log('\nšŸ‘Øā€šŸ³ Chef Michel: ');
67
+
68
+ // Handle the stream
69
+ for await (const chunk of curryResponse.textStream) {
70
+ // Write each chunk without a newline to create a continuous stream
71
+ process.stdout.write(chunk);
72
+ }
73
+
74
+ console.log('\n\nāœ… Recipe complete!');
75
+ }
76
+
77
+ async function generateStream() {
78
+ // Query 2: More ingredients
79
+ const query2 =
80
+ "Now I'm over at my friend's house, and they have: chicken thighs, coconut milk, sweet potatoes, and some curry powder.";
81
+ console.log(`Query 2: ${query2}`);
82
+
83
+ const curryResponse = await agent.stream([query2]);
84
+
85
+ console.log('\nšŸ‘Øā€šŸ³ Chef Michel: ');
86
+
87
+ // Handle the stream
88
+ for await (const chunk of curryResponse.textStream) {
89
+ // Write each chunk without a newline to create a continuous stream
90
+ process.stdout.write(chunk);
91
+ }
92
+
93
+ console.log('\n\nāœ… Recipe complete!');
94
+ }
95
+
96
+ async function textObject() {
97
+ // Query 3: Generate a lasagna recipe
98
+ const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
99
+ console.log(`Query 3: ${query3}`);
100
+
101
+ const lasagnaResponse = await agent.generate(query3, {
102
+ output: z.object({
103
+ ingredients: z.array(
104
+ z.object({
105
+ name: z.string(),
106
+ amount: z.number(),
107
+ }),
108
+ ),
109
+ steps: z.array(z.string()),
110
+ }),
111
+ });
112
+ console.log('\nšŸ‘Øā€šŸ³ Chef Michel:', lasagnaResponse.object);
113
+ console.log('\n-------------------\n');
114
+ }
115
+
116
+ async function experimentalTextObject() {
117
+ // Query 3: Generate a lasagna recipe
118
+ const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
119
+ console.log(`Query 3: ${query3}`);
120
+
121
+ const lasagnaResponse = await agent.generate(query3, {
122
+ experimental_output: z.object({
123
+ ingredients: z.array(
124
+ z.object({
125
+ name: z.string(),
126
+ amount: z.number(),
127
+ }),
128
+ ),
129
+ steps: z.array(z.string()),
130
+ }),
131
+ });
132
+ console.log('\nšŸ‘Øā€šŸ³ Chef Michel:', lasagnaResponse.object);
133
+ console.log('\n-------------------\n');
134
+ }
135
+
136
+ async function textObjectJsonSchema() {
137
+ // Query 3: Generate a lasagna recipe
138
+ const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
139
+ console.log(`Query 3: ${query3}`);
140
+
141
+ const lasagnaResponse = await agent.generate(query3, {
142
+ output: {
143
+ type: 'object',
144
+ additionalProperties: false,
145
+ required: ['ingredients', 'steps'],
146
+ properties: {
147
+ ingredients: {
148
+ type: 'array',
149
+ items: {
150
+ type: 'object',
151
+ additionalProperties: false,
152
+ properties: {
153
+ name: { type: 'string' },
154
+ amount: { type: 'number' },
155
+ },
156
+ required: ['name', 'amount'],
157
+ },
158
+ },
159
+ steps: {
160
+ type: 'array',
161
+ items: { type: 'string' },
162
+ },
163
+ },
164
+ },
165
+ });
166
+
167
+ console.log('\nšŸ‘Øā€šŸ³ Chef Michel:', lasagnaResponse.object);
168
+ console.log('\n-------------------\n');
169
+ }
170
+
171
+ async function generateObject() {
172
+ // Query 3: Generate a lasagna recipe
173
+ const query3 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
174
+ console.log(`Query 3: ${query3}`);
175
+
176
+ const lasagnaResponse = await agent.generate([query3], {
177
+ output: z.object({
178
+ ingredients: z.array(
179
+ z.object({
180
+ name: z.string(),
181
+ amount: z.number(),
182
+ }),
183
+ ),
184
+ steps: z.array(z.string()),
185
+ }),
186
+ });
187
+ console.log('\nšŸ‘Øā€šŸ³ Chef Michel:', lasagnaResponse.object);
188
+ console.log('\n-------------------\n');
189
+ }
190
+
191
+ async function streamObject() {
192
+ // Query 8: Generate a lasagna recipe
193
+ const query8 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
194
+ console.log(`Query 8: ${query8}`);
195
+
196
+ const lasagnaStreamResponse = await agent.stream(query8, {
197
+ output: z.object({
198
+ ingredients: z.array(
199
+ z.object({
200
+ name: z.string(),
201
+ amount: z.number(),
202
+ }),
203
+ ),
204
+ steps: z.array(z.string()),
205
+ }),
206
+ });
207
+
208
+ console.log('\nšŸ‘Øā€šŸ³ Chef Michel: ');
209
+
210
+ // Handle the stream
211
+ for await (const chunk of lasagnaStreamResponse.textStream) {
212
+ // Write each chunk without a newline to create a continuous stream
213
+ process.stdout.write(chunk);
214
+ }
215
+
216
+ console.log('\n\nāœ… Recipe complete!');
217
+ }
218
+
219
+ async function generateStreamObject() {
220
+ // Query 9: Generate a lasagna recipe
221
+ const query9 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
222
+ console.log(`Query 9: ${query9}`);
223
+
224
+ const lasagnaStreamResponse = await agent.stream([query9], {
225
+ output: z.object({
226
+ ingredients: z.array(
227
+ z.object({
228
+ name: z.string(),
229
+ amount: z.number(),
230
+ }),
231
+ ),
232
+ steps: z.array(z.string()),
233
+ }),
234
+ });
235
+
236
+ console.log('\nšŸ‘Øā€šŸ³ Chef Michel: ');
237
+
238
+ // Handle the stream
239
+ for await (const chunk of lasagnaStreamResponse.textStream) {
240
+ // Write each chunk without a newline to create a continuous stream
241
+ process.stdout.write(chunk);
242
+ }
243
+
244
+ console.log('\n\nāœ… Recipe complete!');
245
+ }
246
+
247
+ async function generateExperimentalStreamObject() {
248
+ // Query 9: Generate a lasagna recipe
249
+ const query9 = 'I want to make lasagna, can you generate a lasagna recipe for me?';
250
+ console.log(`Query 9: ${query9}`);
251
+
252
+ const lasagnaStreamResponse = await agent.stream([query9], {
253
+ experimental_output: z.object({
254
+ ingredients: z.array(
255
+ z.object({
256
+ name: z.string(),
257
+ amount: z.number(),
258
+ }),
259
+ ),
260
+ steps: z.array(z.string()),
261
+ }),
262
+ });
263
+
264
+ console.log('\nšŸ‘Øā€šŸ³ Chef Michel: ');
265
+
266
+ // Handle the stream
267
+ for await (const chunk of lasagnaStreamResponse.textStream) {
268
+ // Write each chunk without a newline to create a continuous stream
269
+ process.stdout.write(chunk);
270
+ }
271
+
272
+ console.log('\n\nāœ… Recipe complete!');
273
+ }
274
+
275
+ async function main() {
276
+ // await text();
277
+
278
+ // await experimentalTextObject();
279
+
280
+ // await generateExperimentalStreamObject();
281
+
282
+ // await generateText();
283
+
284
+ // await textStream();
285
+
286
+ // await generateStream();
287
+
288
+ // await textObject();
289
+
290
+ // await textObjectJsonSchema();
291
+
292
+ // await generateObject();
293
+
294
+ // await streamObject();
295
+
296
+ // await generateStreamObject();
297
+
298
+ const query1 = 'What happened in San Francisco last week?';
299
+
300
+ const pastaResponse = await responsesAgent.generate(query1, {
301
+ instructions: 'You take every recipe you get an exaggerate it and use weird ingredients.',
302
+ });
303
+
304
+ console.log(pastaResponse.text);
305
+ }
306
+
307
+ main();
308
+
309
+ ```
310
+
311
+ ### mastra/agents/index.ts
312
+ ```typescript
313
+ import { openai } from '@ai-sdk/openai';
314
+ import { Agent } from '@mastra/core/agent';
315
+ import { cookingTool } from '../tools/index.js';
316
+
317
+ export const chefAgent = new Agent({
318
+ name: 'Chef Agent',
319
+ instructions: `
320
+ YOU MUST USE THE TOOL cooking-tool
321
+ You are Michel, a practical and experienced home chef who helps people cook great meals with whatever
322
+ ingredients they have available. Your first priority is understanding what ingredients and equipment the user has access to, then suggesting achievable recipes.
323
+ You explain cooking steps clearly and offer substitutions when needed, maintaining a friendly and encouraging tone throughout.
324
+ `,
325
+ model: openai('gpt-4o-mini'),
326
+ tools: {
327
+ cookingTool,
328
+ },
329
+ });
330
+
331
+ export const chefAgentResponses = new Agent({
332
+ name: 'Chef Agent',
333
+ instructions: `
334
+ You are Michel, a practical and experienced home chef who helps people cook great meals with whatever
335
+ ingredients they have available. Your first priority is understanding what ingredients and equipment the user has access to, then suggesting achievable recipes.
336
+ You explain cooking steps clearly and offer substitutions when needed, maintaining a friendly and encouraging tone throughout.
337
+ `,
338
+ model: openai.responses('gpt-4o'),
339
+ tools: {
340
+ web_search_preview: openai.tools.webSearchPreview(),
341
+ },
342
+ });
343
+
344
+ ```
345
+
346
+ ### mastra/index.ts
347
+ ```typescript
348
+ import { Mastra } from '@mastra/core';
349
+ import { createLogger } from '@mastra/core/logger';
350
+
351
+ import { chefAgent, chefAgentResponses } from './agents/index';
352
+
353
+ export const mastra = new Mastra({
354
+ agents: { chefAgent, chefAgentResponses },
355
+ logger: createLogger({ name: 'Chef', level: 'info' }),
356
+ serverMiddleware: [
357
+ {
358
+ handler: (c, next) => {
359
+ console.log('Middleware called');
360
+ return next();
361
+ },
362
+ },
363
+ ],
364
+ });
365
+
366
+ ```
367
+
368
+ ### mastra/tools/index.ts
369
+ ```typescript
370
+ import { createTool } from '@mastra/core/tools';
371
+ import { z } from 'zod';
372
+
373
+ export const cookingTool = createTool({
374
+ id: 'cooking-tool',
375
+ description: 'My tool description',
376
+ inputSchema: z.object({
377
+ ingredient: z.string(),
378
+ }),
379
+ execute: async ({ context }, options) => {
380
+ console.log('My tool is running!', context.ingredient);
381
+ if (options?.toolCallId) {
382
+ console.log('Tool call ID:', options.toolCallId);
383
+ }
384
+ return 'My tool result';
385
+ },
386
+ });
387
+
388
+ ```