import { Agent } from "@mastra/core/agent";
import { z } from "zod";
// Agent creation
const agent = new Agent({
id: "my-agent",
name: "my-agent",
description: "Test agent",
instructions: "You are a helpful assistant",
model: "openai/gpt-4o",
tools: {
// ... tools if any
},
memory: undefined, // or memory instance
});
const outputSchema = z.object({
response: z.string(),
status: z.enum(["success", "error"]),
});
// Calling generate with structuredOutput.model
async function testGenerate() {
try {
const response = await agent.generate(
[{ role: "user", content: "Hello" }],
{
structuredOutput: {
schema: outputSchema,
model: "openai/gpt-4o-mini",
},
resourceId: "test-resource",
threadId: "test-thread",
modelSettings: {
temperature: 0.7,
},
}
);
console.log(response.object);
} catch (error) {
console.error(error);
// Error: promise 'text' was not resolved or rejected when stream finished
}
}
import { Agent } from "@mastra/core/agent";
import { z } from "zod";
// Agent creation
const agent = new Agent({
id: "my-agent",
name: "my-agent",
description: "Test agent",
instructions: "You are a helpful assistant",
model: "openai/gpt-4o",
tools: {
// ... tools if any
},
memory: undefined, // or memory instance
});
const outputSchema = z.object({
response: z.string(),
status: z.enum(["success", "error"]),
});
// Calling generate with structuredOutput.model
async function testGenerate() {
try {
const response = await agent.generate(
[{ role: "user", content: "Hello" }],
{
structuredOutput: {
schema: outputSchema,
model: "openai/gpt-4o-mini",
},
resourceId: "test-resource",
threadId: "test-thread",
modelSettings: {
temperature: 0.7,
},
}
);
console.log(response.object);
} catch (error) {
console.error(error);
// Error: promise 'text' was not resolved or rejected when stream finished
}
}