@agentproto/mastra 0.1.0
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.
- package/LICENSE +1 -0
- package/README.md +107 -0
- package/dist/build-agent.d.ts +14 -0
- package/dist/build-agent.d.ts.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +156 -0
- package/dist/index.mjs.map +1 -0
- package/dist/instructions.d.ts +25 -0
- package/dist/instructions.d.ts.map +1 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MIT License — Copyright (c) 2026 agentproto contributors
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# @agentproto/mastra
|
|
2
|
+
|
|
3
|
+
AIP-42 `AGENT.md` → Mastra runtime adapter. Reference implementation
|
|
4
|
+
for the **agent/v1 → live agent** path against the Mastra framework.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pnpm add @agentproto/mastra @agentproto/agent @mastra/core
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Why
|
|
11
|
+
|
|
12
|
+
`@agentproto/agent` parses an `AGENT.md` and gives you a typed
|
|
13
|
+
`AgentHandle`. That's the spec layer. To actually *run* the agent,
|
|
14
|
+
something has to translate ref strings (`anthropic/claude-opus-4-7`,
|
|
15
|
+
`@agentik/tools-standard/web-fetch`, `per-conversation` memory scope)
|
|
16
|
+
into runtime objects.
|
|
17
|
+
|
|
18
|
+
This package is that something for Mastra.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { readFile } from "node:fs/promises"
|
|
24
|
+
import { parseAgentManifest, agentFromManifest } from "@agentproto/agent"
|
|
25
|
+
import { buildMastraAgent } from "@agentproto/mastra"
|
|
26
|
+
import { openai } from "@ai-sdk/openai"
|
|
27
|
+
import { anthropic } from "@ai-sdk/anthropic"
|
|
28
|
+
import { Memory } from "@mastra/memory"
|
|
29
|
+
import { weatherTool } from "./tools/weather"
|
|
30
|
+
|
|
31
|
+
const source = await readFile("./.agents/writer/AGENT.md", "utf8")
|
|
32
|
+
const parsed = parseAgentManifest(source)
|
|
33
|
+
const handle = agentFromManifest(parsed)
|
|
34
|
+
|
|
35
|
+
const { agent, resolvedTools, droppedTools, instructions } =
|
|
36
|
+
await buildMastraAgent(handle, {
|
|
37
|
+
body: parsed.body,
|
|
38
|
+
resolveModel: (ref) => {
|
|
39
|
+
const id = typeof ref === "string" ? ref : (ref.ref ?? "")
|
|
40
|
+
const [provider, model] = id.split("/", 2)
|
|
41
|
+
if (provider === "anthropic") return anthropic(model!)
|
|
42
|
+
if (provider === "openai") return openai(model!)
|
|
43
|
+
throw new Error(`unknown model provider: ${provider}`)
|
|
44
|
+
},
|
|
45
|
+
resolveTool: (ref) => {
|
|
46
|
+
const id = typeof ref === "string" ? ref : (ref.ref ?? "")
|
|
47
|
+
if (id === "weather") return { name: "weather", tool: weatherTool }
|
|
48
|
+
return undefined // dropped with a warning
|
|
49
|
+
},
|
|
50
|
+
buildMemory: (cfg) => new Memory({ /* translate cfg fields */ }),
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
console.log(`built agent '${agent.name}' with ${resolvedTools.length} tools`)
|
|
54
|
+
const reply = await agent.generate("draft a 200-word brief on…")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Resolvers
|
|
58
|
+
|
|
59
|
+
The package never bundles a model provider, tool catalog, or memory
|
|
60
|
+
backend. You provide:
|
|
61
|
+
|
|
62
|
+
| Option | Required | Purpose |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| `resolveModel(ref)` | yes | Translate `model:` → AI-SDK `LanguageModel` |
|
|
65
|
+
| `resolveTool(ref)` | no | Translate `tools[]` → Mastra tools |
|
|
66
|
+
| `resolveWorkflow(ref)` | no | Validate `workflows[]` exist (not attached to agent) |
|
|
67
|
+
| `buildMemory(cfg)` | no | Build a Mastra `Memory` from `memory:` |
|
|
68
|
+
| `buildVoice(handle)` | no | Build a voice provider (ElevenLabs, etc.) |
|
|
69
|
+
| `formatInstructions` | no | Override how body + boundaries become a system prompt |
|
|
70
|
+
| `body` | no | The markdown body (everything after frontmatter) |
|
|
71
|
+
| `strict` | no | Throw on unresolved tools instead of warn-and-drop |
|
|
72
|
+
|
|
73
|
+
## Default instructions composer
|
|
74
|
+
|
|
75
|
+
`composeInstructions(handle, body)` produces:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
{body or description}
|
|
79
|
+
|
|
80
|
+
{persona inline block if present}
|
|
81
|
+
|
|
82
|
+
Hard rules — these MUST be followed:
|
|
83
|
+
- {boundary 1}
|
|
84
|
+
- {boundary 2}
|
|
85
|
+
|
|
86
|
+
Trait scores (0-10): rigor=9, warmth=4.
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Override with `formatInstructions: (handle, body) => string` if your
|
|
90
|
+
host has its own prompt assembly (e.g. multi-agent council headers,
|
|
91
|
+
per-tenant pre-amble, i18n).
|
|
92
|
+
|
|
93
|
+
## Diagnostics
|
|
94
|
+
|
|
95
|
+
`buildMastraAgent` returns the live `Agent` plus:
|
|
96
|
+
|
|
97
|
+
- `resolvedTools: string[]` — names that wired in
|
|
98
|
+
- `droppedTools: string[]` — refs the resolver returned `undefined` for
|
|
99
|
+
- `resolvedWorkflows: string[]` / `droppedWorkflows: string[]`
|
|
100
|
+
- `instructions: string` — the final composed prompt
|
|
101
|
+
|
|
102
|
+
Useful for diagnostics UIs (which tools were declared on the manifest
|
|
103
|
+
but missing from the host's catalog?) and tests.
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `buildMastraAgent(handle, opts)` — turn an AIP-42 AGENT.md handle
|
|
3
|
+
* into a runnable `new Agent({ ... })` from `@mastra/core/agent`.
|
|
4
|
+
*
|
|
5
|
+
* The function is intentionally narrow: it walks the manifest's
|
|
6
|
+
* structural fields and calls user-supplied resolvers for everything
|
|
7
|
+
* that needs runtime knowledge (model, tools, workflows, memory,
|
|
8
|
+
* voice). Anything the resolvers can't translate is either dropped
|
|
9
|
+
* with a warning (default) or throws (`strict: true`).
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentHandle } from "@agentproto/agent";
|
|
12
|
+
import type { BuildMastraAgentOptions, BuildMastraAgentResult } from "./types.js";
|
|
13
|
+
export declare function buildMastraAgent(handle: AgentHandle, opts: BuildMastraAgentOptions): Promise<BuildMastraAgentResult>;
|
|
14
|
+
//# sourceMappingURL=build-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-agent.d.ts","sourceRoot":"","sources":["../src/build-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAU,MAAM,mBAAmB,CAAA;AAE5D,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EAIvB,MAAM,YAAY,CAAA;AAEnB,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,sBAAsB,CAAC,CAgDjC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @agentproto/mastra — AIP-42 AGENT.md → Mastra runtime adapter.
|
|
3
|
+
*
|
|
4
|
+
* Public surface:
|
|
5
|
+
* - `buildMastraAgent(handle, opts)` — build a `new Agent({...})`
|
|
6
|
+
* from a parsed AGENT.md handle, given resolvers for model/tools/
|
|
7
|
+
* workflows/memory.
|
|
8
|
+
* - `composeInstructions(handle, body)` — default body→prompt
|
|
9
|
+
* composer. Override via `opts.formatInstructions`.
|
|
10
|
+
* - resolver / option / result types for typed integration.
|
|
11
|
+
*
|
|
12
|
+
* Mastra is a peer dependency. Install `@mastra/core` (>=1.x) in the
|
|
13
|
+
* host package; this adapter doesn't bundle it.
|
|
14
|
+
*/
|
|
15
|
+
export { buildMastraAgent } from "./build-agent.js";
|
|
16
|
+
export { composeInstructions } from "./instructions.js";
|
|
17
|
+
export type { BuildMastraAgentOptions, BuildMastraAgentResult, ModelResolver, ToolResolver, WorkflowResolver, MemoryBuilder, VoiceBuilder, InstructionsFormatter, LanguageModelLike, MastraToolLike, MastraMemoryLike, MastraVoiceLike, MastraWorkflowLike, AgentHandle, AnyRef, ActionRef, ModelRef, MemoryConfig, } from "./types.js";
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,WAAW,EACX,MAAM,EACN,SAAS,EACT,QAAQ,EACR,YAAY,GACb,MAAM,YAAY,CAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Agent } from '@mastra/core/agent';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @agentproto/mastra v0.1.0-alpha
|
|
5
|
+
* AIP-42 AGENT.md → Mastra runtime adapter.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// src/instructions.ts
|
|
10
|
+
var HEADER_RULE = "Hard rules \u2014 these MUST be followed:";
|
|
11
|
+
function composeInstructions(handle, body) {
|
|
12
|
+
const parts = [];
|
|
13
|
+
parts.push(body?.trim() ?? handle.description.trim());
|
|
14
|
+
const personaInline = extractPersonaInline(handle);
|
|
15
|
+
if (personaInline) parts.push(personaInline);
|
|
16
|
+
if (handle.boundaries && handle.boundaries.length > 0) {
|
|
17
|
+
const lines = handle.boundaries.map((b) => `- ${b}`).join("\n");
|
|
18
|
+
parts.push(`${HEADER_RULE}
|
|
19
|
+
${lines}`);
|
|
20
|
+
}
|
|
21
|
+
if (handle.traits && Object.keys(handle.traits).length > 0) {
|
|
22
|
+
parts.push(traitsLine(handle.traits));
|
|
23
|
+
}
|
|
24
|
+
return parts.filter((s) => s.length > 0).join("\n\n");
|
|
25
|
+
}
|
|
26
|
+
function extractPersonaInline(handle) {
|
|
27
|
+
const p = handle.persona;
|
|
28
|
+
if (!p || typeof p === "string") return void 0;
|
|
29
|
+
if (typeof p !== "object" || p === null || !("inline" in p)) return void 0;
|
|
30
|
+
const inline = p.inline;
|
|
31
|
+
if (!inline) return void 0;
|
|
32
|
+
const lines = [];
|
|
33
|
+
if (typeof inline.name === "string") lines.push(`Name: ${inline.name}`);
|
|
34
|
+
if (typeof inline.tone === "string") lines.push(`Tone: ${inline.tone}`);
|
|
35
|
+
if (Array.isArray(inline.values)) {
|
|
36
|
+
lines.push(`Values: ${inline.values.join(", ")}`);
|
|
37
|
+
}
|
|
38
|
+
if (typeof inline.bio === "string") lines.push(inline.bio);
|
|
39
|
+
return lines.length > 0 ? `Persona
|
|
40
|
+
${lines.join("\n")}` : void 0;
|
|
41
|
+
}
|
|
42
|
+
function traitsLine(traits) {
|
|
43
|
+
const formatted = Object.entries(traits).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
44
|
+
return `Trait scores (0-10): ${formatted}.`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/build-agent.ts
|
|
48
|
+
async function buildMastraAgent(handle, opts) {
|
|
49
|
+
const formatInstructions = opts.formatInstructions ?? composeInstructions;
|
|
50
|
+
const instructions = formatInstructions(handle, opts.body);
|
|
51
|
+
const model = await opts.resolveModel(handle.model);
|
|
52
|
+
const { tools, resolvedTools, droppedTools } = await resolveTools(
|
|
53
|
+
handle.tools,
|
|
54
|
+
opts.resolveTool,
|
|
55
|
+
{ strict: opts.strict ?? false, agentId: handle.id }
|
|
56
|
+
);
|
|
57
|
+
const { resolvedWorkflows, droppedWorkflows } = await resolveWorkflows(
|
|
58
|
+
handle.workflows,
|
|
59
|
+
opts.resolveWorkflow,
|
|
60
|
+
{ strict: opts.strict ?? false, agentId: handle.id }
|
|
61
|
+
);
|
|
62
|
+
const memory = opts.buildMemory && handle.memory ? await opts.buildMemory(handle.memory) : void 0;
|
|
63
|
+
const voice = opts.buildVoice ? await opts.buildVoice(handle) : void 0;
|
|
64
|
+
const name = opts.name ?? stripOwner(handle.id);
|
|
65
|
+
const id = opts.id ?? handle.id;
|
|
66
|
+
const agent = new Agent({
|
|
67
|
+
name,
|
|
68
|
+
id,
|
|
69
|
+
instructions,
|
|
70
|
+
model,
|
|
71
|
+
tools,
|
|
72
|
+
memory,
|
|
73
|
+
voice
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
agent,
|
|
77
|
+
resolvedTools,
|
|
78
|
+
droppedTools,
|
|
79
|
+
resolvedWorkflows,
|
|
80
|
+
droppedWorkflows,
|
|
81
|
+
instructions
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async function resolveTools(refs, resolve, ctx) {
|
|
85
|
+
const tools = {};
|
|
86
|
+
const resolvedTools = [];
|
|
87
|
+
const droppedTools = [];
|
|
88
|
+
if (!refs || refs.length === 0) return { tools, resolvedTools, droppedTools };
|
|
89
|
+
if (!resolve) {
|
|
90
|
+
if (ctx.strict) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`buildMastraAgent: agent '${ctx.agentId}' declares ${refs.length} tool(s) but no resolveTool was provided`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
console.warn(
|
|
96
|
+
`[@agentproto/mastra] agent '${ctx.agentId}' declares ${refs.length} tool(s) but no resolveTool was provided \u2014 skipping`
|
|
97
|
+
);
|
|
98
|
+
refs.forEach((r) => droppedTools.push(refKey(r)));
|
|
99
|
+
return { tools, resolvedTools, droppedTools };
|
|
100
|
+
}
|
|
101
|
+
for (const ref of refs) {
|
|
102
|
+
const resolved = await resolve(ref);
|
|
103
|
+
if (!resolved) {
|
|
104
|
+
droppedTools.push(refKey(ref));
|
|
105
|
+
if (ctx.strict) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`buildMastraAgent: agent '${ctx.agentId}' tool '${refKey(ref)}' did not resolve`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
console.warn(
|
|
111
|
+
`[@agentproto/mastra] agent '${ctx.agentId}' tool '${refKey(ref)}' did not resolve \u2014 skipping`
|
|
112
|
+
);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
tools[resolved.name] = resolved.tool;
|
|
116
|
+
resolvedTools.push(resolved.name);
|
|
117
|
+
}
|
|
118
|
+
return { tools, resolvedTools, droppedTools };
|
|
119
|
+
}
|
|
120
|
+
async function resolveWorkflows(refs, resolve, ctx) {
|
|
121
|
+
const resolvedWorkflows = [];
|
|
122
|
+
const droppedWorkflows = [];
|
|
123
|
+
if (!refs || refs.length === 0) {
|
|
124
|
+
return { resolvedWorkflows, droppedWorkflows };
|
|
125
|
+
}
|
|
126
|
+
if (!resolve) {
|
|
127
|
+
refs.forEach((r) => droppedWorkflows.push(refKey(r)));
|
|
128
|
+
return { resolvedWorkflows, droppedWorkflows };
|
|
129
|
+
}
|
|
130
|
+
for (const ref of refs) {
|
|
131
|
+
const resolved = await resolve(ref);
|
|
132
|
+
if (!resolved) {
|
|
133
|
+
droppedWorkflows.push(refKey(ref));
|
|
134
|
+
if (ctx.strict) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`buildMastraAgent: agent '${ctx.agentId}' workflow '${refKey(ref)}' did not resolve`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
resolvedWorkflows.push(resolved.name);
|
|
142
|
+
}
|
|
143
|
+
return { resolvedWorkflows, droppedWorkflows };
|
|
144
|
+
}
|
|
145
|
+
function refKey(ref) {
|
|
146
|
+
if (typeof ref === "string") return ref;
|
|
147
|
+
return ref.ref ?? ref.file ?? JSON.stringify(ref.inline ?? ref);
|
|
148
|
+
}
|
|
149
|
+
function stripOwner(id) {
|
|
150
|
+
const m = id.match(/^@[^/]+\/(.+)$/);
|
|
151
|
+
return m ? m[1] : id;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { buildMastraAgent, composeInstructions };
|
|
155
|
+
//# sourceMappingURL=index.mjs.map
|
|
156
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/instructions.ts","../src/build-agent.ts"],"names":[],"mappings":";;;;;;;;;AAWA,IAAM,WAAA,GAAc,2CAAA;AAgBb,SAAS,mBAAA,CACd,QACA,IAAA,EACQ;AACR,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,KAAA,CAAM,KAAK,IAAA,EAAM,IAAA,MAAU,MAAA,CAAO,WAAA,CAAY,MAAM,CAAA;AAEpD,EAAA,MAAM,aAAA,GAAgB,qBAAqB,MAAM,CAAA;AACjD,EAAA,IAAI,aAAA,EAAe,KAAA,CAAM,IAAA,CAAK,aAAa,CAAA;AAE3C,EAAA,IAAI,MAAA,CAAO,UAAA,IAAc,MAAA,CAAO,UAAA,CAAW,SAAS,CAAA,EAAG;AACrD,IAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,UAAA,CAAW,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAA,CAAE,IAAA,CAAK,IAAI,CAAA;AAC9D,IAAA,KAAA,CAAM,IAAA,CAAK,GAAG,WAAW;AAAA,EAAK,KAAK,C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IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,IAAA,CAAK,OAAA,CAAQ,CAAC,CAAA,KAAM,gBAAA,CAAiB,KAAK,MAAA,CAAO,CAAC,CAAC,CAAC,CAAA;AACpD,IAAA,OAAO,EAAE,mBAAmB,gBAAA,EAAiB;AAAA,EAC/C;AAEA,EAAA,KAAA,MAAW,OAAO,IAAA,EAAM;AACtB,IAAA,MAAM,QAAA,GAAW,MAAM,OAAA,CAAQ,GAAG,CAAA;AAClC,IAAA,IAAI,CAAC,QAAA,EAAU;AACb,MAAA,gBAAA,CAAiB,IAAA,CAAK,MAAA,CAAO,GAAG,CAAC,CAAA;AACjC,MAAA,IAAI,IAAI,MAAA,EAAQ;AACd,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,4BAA4B,GAAA,CAAI,OAAO,CAAA,YAAA,EAAe,MAAA,CAAO,GAAG,CAAC,CAAA,iBAAA;AAAA,SACnE;AAAA,MACF;AACA,MAAA;AAAA,IACF;AACA,IAAA,iBAAA,CAAkB,IAAA,CAAK,SAAS,IAAI,CAAA;AAAA,EACtC;AAEA,EAAA,OAAO,EAAE,mBAAmB,gBAAA,EAAiB;AAC/C;AAEA,SAAS,OAAO,GAAA,EAAqB;AACnC,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,EAAU,OAAO,GAAA;AACpC,EAAA,OAAO,GAAA,CAAI,OAAO,GAAA,CAAI,IAAA,IAAQ,KAAK,SAAA,CAAU,GAAA,CAAI,UAAU,GAAG,CAAA;AAChE;AAEA,SAAS,WAAW,EAAA,EAAoB;AAEtC,EAAA,MAAM,CAAA,GAAI,EAAA,CAAG,KAAA,CAAM,gBAAgB,CAAA;AACnC,EAAA,OAAO,CAAA,GAAI,CAAA,CAAE,CAAC,CAAA,GAAK,EAAA;AACrB","file":"index.mjs","sourcesContent":["/**\n * Default instructions composer.\n *\n * AIP-42 says the markdown body of an AGENT.md is the agent's primary\n * system prompt. Boundaries, persona inline content, and trait scores\n * are appended in that order so the body — the human-authored part —\n * stays at the top where the model sees it first.\n */\n\nimport type { AgentHandle } from \"@agentproto/agent\"\n\nconst HEADER_RULE = \"Hard rules — these MUST be followed:\"\n\n/**\n * Compose the AGENT.md body + structural fields into a system prompt.\n *\n * Order:\n * 1. body (markdown after frontmatter), or `description` if absent\n * 2. inline persona block (when `persona` is `{ inline: ... }`)\n * 3. boundaries (rendered as a bulleted \"hard rules\" block)\n * 4. traits (rendered as a one-line guidance hint when present)\n *\n * Refs (`persona: \"@some/persona\"`) are NOT inlined — the host is\n * expected to resolve them externally and inject them via\n * `formatInstructions` if it cares, or pre-resolve and pass the\n * resolved body in via `body:`.\n */\nexport function composeInstructions(\n handle: AgentHandle,\n body: string | undefined,\n): string {\n const parts: string[] = []\n parts.push(body?.trim() ?? handle.description.trim())\n\n const personaInline = extractPersonaInline(handle)\n if (personaInline) parts.push(personaInline)\n\n if (handle.boundaries && handle.boundaries.length > 0) {\n const lines = handle.boundaries.map((b) => `- ${b}`).join(\"\\n\")\n parts.push(`${HEADER_RULE}\\n${lines}`)\n }\n\n if (handle.traits && Object.keys(handle.traits).length > 0) {\n parts.push(traitsLine(handle.traits))\n }\n\n return parts.filter((s) => s.length > 0).join(\"\\n\\n\")\n}\n\nfunction extractPersonaInline(handle: AgentHandle): string | undefined {\n const p = handle.persona\n if (!p || typeof p === \"string\") return undefined\n if (typeof p !== \"object\" || p === null || !(\"inline\" in p)) return undefined\n const inline = (p as { inline?: Record<string, unknown> }).inline\n if (!inline) return undefined\n const lines: string[] = []\n if (typeof inline.name === \"string\") lines.push(`Name: ${inline.name}`)\n if (typeof inline.tone === \"string\") lines.push(`Tone: ${inline.tone}`)\n if (Array.isArray(inline.values)) {\n lines.push(`Values: ${inline.values.join(\", \")}`)\n }\n if (typeof inline.bio === \"string\") lines.push(inline.bio)\n return lines.length > 0 ? `Persona\\n${lines.join(\"\\n\")}` : undefined\n}\n\nfunction traitsLine(traits: Record<string, number>): string {\n const formatted = Object.entries(traits)\n .map(([k, v]) => `${k}=${v}`)\n .join(\", \")\n return `Trait scores (0-10): ${formatted}.`\n}\n","/**\n * `buildMastraAgent(handle, opts)` — turn an AIP-42 AGENT.md handle\n * into a runnable `new Agent({ ... })` from `@mastra/core/agent`.\n *\n * The function is intentionally narrow: it walks the manifest's\n * structural fields and calls user-supplied resolvers for everything\n * that needs runtime knowledge (model, tools, workflows, memory,\n * voice). Anything the resolvers can't translate is either dropped\n * with a warning (default) or throws (`strict: true`).\n */\n\nimport { Agent } from \"@mastra/core/agent\"\nimport type { AgentHandle, AnyRef } from \"@agentproto/agent\"\nimport { composeInstructions } from \"./instructions.js\"\nimport type {\n BuildMastraAgentOptions,\n BuildMastraAgentResult,\n ToolResolver,\n WorkflowResolver,\n MastraToolLike,\n} from \"./types.js\"\n\nexport async function buildMastraAgent(\n handle: AgentHandle,\n opts: BuildMastraAgentOptions,\n): Promise<BuildMastraAgentResult> {\n const formatInstructions = opts.formatInstructions ?? composeInstructions\n const instructions = formatInstructions(handle, opts.body)\n const model = await opts.resolveModel(handle.model)\n\n const { tools, resolvedTools, droppedTools } = await resolveTools(\n handle.tools,\n opts.resolveTool,\n { strict: opts.strict ?? false, agentId: handle.id },\n )\n\n const { resolvedWorkflows, droppedWorkflows } = await resolveWorkflows(\n handle.workflows,\n opts.resolveWorkflow,\n { strict: opts.strict ?? false, agentId: handle.id },\n )\n\n const memory = opts.buildMemory && handle.memory\n ? await opts.buildMemory(handle.memory)\n : undefined\n\n const voice = opts.buildVoice ? await opts.buildVoice(handle) : undefined\n\n const name = opts.name ?? stripOwner(handle.id)\n const id = opts.id ?? handle.id\n\n // Mastra's Agent ctor types are heterogeneous (model union, tools\n // record etc.) and have generic-variance issues that leak through\n // structuredOutput inference; we widen at both ends so the package\n // stays independent of @mastra/core's internal generic shape.\n const agent = new Agent({\n name,\n id,\n instructions,\n model,\n tools,\n memory,\n voice,\n } as unknown as ConstructorParameters<typeof Agent>[0]) as unknown as Agent\n\n return {\n agent,\n resolvedTools,\n droppedTools,\n resolvedWorkflows,\n droppedWorkflows,\n instructions,\n }\n}\n\ninterface ResolveToolsCtx {\n strict: boolean\n agentId: string\n}\n\nasync function resolveTools(\n refs: AnyRef[] | undefined,\n resolve: ToolResolver | undefined,\n ctx: ResolveToolsCtx,\n): Promise<{\n tools: Record<string, MastraToolLike>\n resolvedTools: string[]\n droppedTools: string[]\n}> {\n const tools: Record<string, MastraToolLike> = {}\n const resolvedTools: string[] = []\n const droppedTools: string[] = []\n\n if (!refs || refs.length === 0) return { tools, resolvedTools, droppedTools }\n\n if (!resolve) {\n if (ctx.strict) {\n throw new Error(\n `buildMastraAgent: agent '${ctx.agentId}' declares ${refs.length} tool(s) but no resolveTool was provided`,\n )\n }\n console.warn(\n `[@agentproto/mastra] agent '${ctx.agentId}' declares ${refs.length} tool(s) but no resolveTool was provided — skipping`,\n )\n refs.forEach((r) => droppedTools.push(refKey(r)))\n return { tools, resolvedTools, droppedTools }\n }\n\n for (const ref of refs) {\n const resolved = await resolve(ref)\n if (!resolved) {\n droppedTools.push(refKey(ref))\n if (ctx.strict) {\n throw new Error(\n `buildMastraAgent: agent '${ctx.agentId}' tool '${refKey(ref)}' did not resolve`,\n )\n }\n console.warn(\n `[@agentproto/mastra] agent '${ctx.agentId}' tool '${refKey(ref)}' did not resolve — skipping`,\n )\n continue\n }\n tools[resolved.name] = resolved.tool\n resolvedTools.push(resolved.name)\n }\n\n return { tools, resolvedTools, droppedTools }\n}\n\nasync function resolveWorkflows(\n refs: AnyRef[] | undefined,\n resolve: WorkflowResolver | undefined,\n ctx: ResolveToolsCtx,\n): Promise<{ resolvedWorkflows: string[]; droppedWorkflows: string[] }> {\n const resolvedWorkflows: string[] = []\n const droppedWorkflows: string[] = []\n\n if (!refs || refs.length === 0) {\n return { resolvedWorkflows, droppedWorkflows }\n }\n if (!resolve) {\n refs.forEach((r) => droppedWorkflows.push(refKey(r)))\n return { resolvedWorkflows, droppedWorkflows }\n }\n\n for (const ref of refs) {\n const resolved = await resolve(ref)\n if (!resolved) {\n droppedWorkflows.push(refKey(ref))\n if (ctx.strict) {\n throw new Error(\n `buildMastraAgent: agent '${ctx.agentId}' workflow '${refKey(ref)}' did not resolve`,\n )\n }\n continue\n }\n resolvedWorkflows.push(resolved.name)\n }\n\n return { resolvedWorkflows, droppedWorkflows }\n}\n\nfunction refKey(ref: AnyRef): string {\n if (typeof ref === \"string\") return ref\n return ref.ref ?? ref.file ?? JSON.stringify(ref.inline ?? ref)\n}\n\nfunction stripOwner(id: string): string {\n // `@agentik/writer` → `writer`; bare ids untouched.\n const m = id.match(/^@[^/]+\\/(.+)$/)\n return m ? m[1]! : id\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default instructions composer.
|
|
3
|
+
*
|
|
4
|
+
* AIP-42 says the markdown body of an AGENT.md is the agent's primary
|
|
5
|
+
* system prompt. Boundaries, persona inline content, and trait scores
|
|
6
|
+
* are appended in that order so the body — the human-authored part —
|
|
7
|
+
* stays at the top where the model sees it first.
|
|
8
|
+
*/
|
|
9
|
+
import type { AgentHandle } from "@agentproto/agent";
|
|
10
|
+
/**
|
|
11
|
+
* Compose the AGENT.md body + structural fields into a system prompt.
|
|
12
|
+
*
|
|
13
|
+
* Order:
|
|
14
|
+
* 1. body (markdown after frontmatter), or `description` if absent
|
|
15
|
+
* 2. inline persona block (when `persona` is `{ inline: ... }`)
|
|
16
|
+
* 3. boundaries (rendered as a bulleted "hard rules" block)
|
|
17
|
+
* 4. traits (rendered as a one-line guidance hint when present)
|
|
18
|
+
*
|
|
19
|
+
* Refs (`persona: "@some/persona"`) are NOT inlined — the host is
|
|
20
|
+
* expected to resolve them externally and inject them via
|
|
21
|
+
* `formatInstructions` if it cares, or pre-resolve and pass the
|
|
22
|
+
* resolved body in via `body:`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function composeInstructions(handle: AgentHandle, body: string | undefined): string;
|
|
25
|
+
//# sourceMappingURL=instructions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../src/instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAIpD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,MAAM,CAiBR"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolver and option types used by `buildMastraAgent`.
|
|
3
|
+
*
|
|
4
|
+
* The package never bakes in a model provider, a tool registry, or a
|
|
5
|
+
* memory backend — those are runtime concerns the host owns. We expose
|
|
6
|
+
* the manifest fields as ref values and let the host translate.
|
|
7
|
+
*/
|
|
8
|
+
import type { Agent } from "@mastra/core/agent";
|
|
9
|
+
import type { AgentHandle, AnyRef, ActionRef, ModelRef, MemoryConfig } from "@agentproto/agent";
|
|
10
|
+
export type LanguageModelLike = unknown;
|
|
11
|
+
export type MastraToolLike = unknown;
|
|
12
|
+
export type MastraMemoryLike = unknown;
|
|
13
|
+
export type MastraVoiceLike = unknown;
|
|
14
|
+
export type MastraWorkflowLike = unknown;
|
|
15
|
+
/**
|
|
16
|
+
* Resolves an AIP-42 `model:` ref to whatever the host's `new Agent`
|
|
17
|
+
* constructor accepts as `model`. Throws if the ref can't be resolved.
|
|
18
|
+
*/
|
|
19
|
+
export type ModelResolver = (ref: ModelRef) => LanguageModelLike | Promise<LanguageModelLike>;
|
|
20
|
+
/**
|
|
21
|
+
* Resolves a tool ref. Returning `undefined` skips the tool (with a
|
|
22
|
+
* warning) — useful when the host's tool catalog is partial. The
|
|
23
|
+
* returned tool name is taken from the ref string when available;
|
|
24
|
+
* structured refs should set `id` on the tool itself.
|
|
25
|
+
*/
|
|
26
|
+
export type ToolResolver = (ref: AnyRef) => {
|
|
27
|
+
name: string;
|
|
28
|
+
tool: MastraToolLike;
|
|
29
|
+
} | undefined | Promise<{
|
|
30
|
+
name: string;
|
|
31
|
+
tool: MastraToolLike;
|
|
32
|
+
} | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Resolves a workflow ref. Workflows aren't passed to `new Agent`
|
|
35
|
+
* directly in Mastra — they're registered on the Mastra instance —
|
|
36
|
+
* but the resolver is invoked here so the host can validate that
|
|
37
|
+
* every `workflows[]` entry on the manifest exists in the registry.
|
|
38
|
+
*/
|
|
39
|
+
export type WorkflowResolver = (ref: AnyRef) => {
|
|
40
|
+
name: string;
|
|
41
|
+
workflow: MastraWorkflowLike;
|
|
42
|
+
} | undefined | Promise<{
|
|
43
|
+
name: string;
|
|
44
|
+
workflow: MastraWorkflowLike;
|
|
45
|
+
} | undefined>;
|
|
46
|
+
/**
|
|
47
|
+
* Builds a Mastra `Memory` instance from the manifest's `memory:`
|
|
48
|
+
* block. Return `undefined` to attach no memory (Mastra default).
|
|
49
|
+
*/
|
|
50
|
+
export type MemoryBuilder = (config: MemoryConfig) => MastraMemoryLike | undefined | Promise<MastraMemoryLike | undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* Builds a voice provider for runtime voice/audio agents. Optional;
|
|
53
|
+
* only invoked when the host opts in via `withVoice`.
|
|
54
|
+
*/
|
|
55
|
+
export type VoiceBuilder = (handle: AgentHandle) => MastraVoiceLike | undefined | Promise<MastraVoiceLike | undefined>;
|
|
56
|
+
/**
|
|
57
|
+
* Composes the system prompt the agent runs under. Defaults to
|
|
58
|
+
* `composeInstructions(handle, body)` from `./instructions.ts`.
|
|
59
|
+
*/
|
|
60
|
+
export type InstructionsFormatter = (handle: AgentHandle, body: string | undefined) => string;
|
|
61
|
+
export interface BuildMastraAgentOptions {
|
|
62
|
+
/** Required. Maps `model:` to a Mastra-compatible LanguageModel. */
|
|
63
|
+
resolveModel: ModelResolver;
|
|
64
|
+
/** Optional. Without it, `tools[]` is dropped with a console.warn. */
|
|
65
|
+
resolveTool?: ToolResolver;
|
|
66
|
+
/** Optional. Validates that workflows exist; result not attached to Agent. */
|
|
67
|
+
resolveWorkflow?: WorkflowResolver;
|
|
68
|
+
/** Optional. Attaches Mastra Memory to the Agent. */
|
|
69
|
+
buildMemory?: MemoryBuilder;
|
|
70
|
+
/** Optional. Attaches a voice provider (ElevenLabs etc.) to the Agent. */
|
|
71
|
+
buildVoice?: VoiceBuilder;
|
|
72
|
+
/** Optional. Override how AGENT.md body + boundaries become instructions. */
|
|
73
|
+
formatInstructions?: InstructionsFormatter;
|
|
74
|
+
/**
|
|
75
|
+
* Optional. The markdown body of the AGENT.md (everything after
|
|
76
|
+
* frontmatter). When absent, instructions fall back to `description`.
|
|
77
|
+
*/
|
|
78
|
+
body?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Optional. Override the agent's display name. Defaults to
|
|
81
|
+
* `handle.id` (with the `@<owner>/` prefix stripped).
|
|
82
|
+
*/
|
|
83
|
+
name?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Optional. Override the agent's stable id. Defaults to `handle.id`.
|
|
86
|
+
*/
|
|
87
|
+
id?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Optional. If a tool ref can't be resolved, throw instead of
|
|
90
|
+
* silently dropping. Defaults to `false` (warn + drop).
|
|
91
|
+
*/
|
|
92
|
+
strict?: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Result of `buildMastraAgent`. Returns the Agent + diagnostics about
|
|
96
|
+
* what got resolved vs dropped, useful for tests and surface UIs.
|
|
97
|
+
*/
|
|
98
|
+
export interface BuildMastraAgentResult {
|
|
99
|
+
agent: Agent;
|
|
100
|
+
/** Tool refs that resolved successfully (by name). */
|
|
101
|
+
resolvedTools: string[];
|
|
102
|
+
/** Tool refs that the resolver returned `undefined` for. */
|
|
103
|
+
droppedTools: string[];
|
|
104
|
+
/** Workflow refs that resolved successfully. */
|
|
105
|
+
resolvedWorkflows: string[];
|
|
106
|
+
/** Workflow refs that the resolver returned `undefined` for. */
|
|
107
|
+
droppedWorkflows: string[];
|
|
108
|
+
/** The composed instructions string. */
|
|
109
|
+
instructions: string;
|
|
110
|
+
}
|
|
111
|
+
export type { AgentHandle, AnyRef, ActionRef, ModelRef, MemoryConfig, };
|
|
112
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,EACV,WAAW,EACX,MAAM,EACN,SAAS,EACT,QAAQ,EACR,YAAY,EACb,MAAM,mBAAmB,CAAA;AAO1B,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAA;AACvC,MAAM,MAAM,cAAc,GAAG,OAAO,CAAA;AACpC,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAA;AACtC,MAAM,MAAM,eAAe,GAAG,OAAO,CAAA;AACrC,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAA;AAExC;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAC1B,GAAG,EAAE,QAAQ,KACV,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AAEnD;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,CACzB,GAAG,EAAE,MAAM,KAET;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,GACtC,SAAS,GACT,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,GAAG,SAAS,CAAC,CAAA;AAE/D;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,GAAG,EAAE,MAAM,KAET;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,kBAAkB,CAAA;CAAE,GAC9C,SA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AA;IACtB,gDAAgD;IAChD,iBAAiB,EAAE,MAAM,EAAE,CAAA;IAC3B,gEAAgE;IAChE,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,YAAY,EACV,WAAW,EACX,MAAM,EACN,SAAS,EACT,QAAQ,EACR,YAAY,GACb,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentproto/mastra",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "@agentproto/mastra — turn an AIP-42 AGENT.md handle into a runnable Mastra Agent. The package is a thin adapter: you supply resolvers (model, tool, workflow, memory) and it composes the manifest's identity, persona, body, boundaries, and tool refs into a constructed `new Agent({...})` from `@mastra/core/agent`. Reference implementation for the agent/v1 → Mastra runtime path.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agentproto",
|
|
7
|
+
"aip-42",
|
|
8
|
+
"mastra",
|
|
9
|
+
"agent",
|
|
10
|
+
"runtime",
|
|
11
|
+
"adapter",
|
|
12
|
+
"open-standard"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://agentproto.sh/docs/aip-42",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/agentproto/ts",
|
|
18
|
+
"directory": "packages/mastra"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/agentproto/ts/issues"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "dist/index.mjs",
|
|
26
|
+
"module": "dist/index.mjs",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.mjs",
|
|
32
|
+
"default": "./dist/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@agentproto/agent": "0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@mastra/core": ">=1.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@mastra/core": "1.32.1",
|
|
52
|
+
"@types/node": "^25.6.2",
|
|
53
|
+
"tsup": "^8.5.1",
|
|
54
|
+
"typescript": "^5.9.3",
|
|
55
|
+
"vitest": "^3.2.4",
|
|
56
|
+
"@agentproto/tooling": "0.1.0-alpha.0"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"dev": "tsup --watch",
|
|
60
|
+
"build": "tsup && tsc -p tsconfig.build.json",
|
|
61
|
+
"clean": "rm -rf dist",
|
|
62
|
+
"check-types": "tsc --noEmit",
|
|
63
|
+
"test": "vitest run",
|
|
64
|
+
"test:watch": "vitest"
|
|
65
|
+
}
|
|
66
|
+
}
|