Skip to content

[BUG] Can‘t set instructions dynamiclly #3837

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Open
2 tasks done
huyannb opened this issue Apr 27, 2025 · 2 comments
Open
2 tasks done

[BUG] Can‘t set instructions dynamiclly #3837

huyannb opened this issue Apr 27, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@huyannb
Copy link

huyannb commented Apr 27, 2025

Describe the Bug

code from https://mastra.ai/blog/dynamic-agents

const dynamicAgent = new Agent({
  tools: ({ runtimeContext }) => {
    // Use runtimeContext.get() to access variables
    const temperatureScale = runtimeContext.get("temperature-scale");
    return temperatureScale === "celsius" ? celsiusTools : fahrenheitTools;
  },
  **instructions: ({ runtimeContext }) => {
    const temperatureScale = runtimeContext.get("temperature-scale");
    return `You are assisting with ${temperatureScale} temperature.`;
  },**
  model: ({ runtimeContext }) => {
    return runtimeContext.get("preferFast")
      ? openai("gpt-4o-mini")
      : openai("gpt-4o");
  },
});

but instructions like this is invalid on mastra@0.9.0.

Steps To Reproduce

  1. install latest mastra
  2. set a dynamic agent followed by https://mastra.ai/blog/dynamic-agents
  3. IDE will raise error

Expected Behavior

instructions should be able to declared dymanicly

Environment Information

None

Component

Agents

Code Snippet

const dynamicAgent = new Agent({
  tools: ({ runtimeContext }) => {
    // Use runtimeContext.get() to access variables
    const temperatureScale = runtimeContext.get("temperature-scale");
    return temperatureScale === "celsius" ? celsiusTools : fahrenheitTools;
  },
  **instructions: ({ runtimeContext }) => {
    const temperatureScale = runtimeContext.get("temperature-scale");
    return `You are assisting with ${temperatureScale} temperature.`;
  },**
  model: ({ runtimeContext }) => {
    return runtimeContext.get("preferFast")
      ? openai("gpt-4o-mini")
      : openai("gpt-4o");
  },
});

Error Logs

Additional Context

No response

Verification

  • I have searched the existing issues to make sure this is not a duplicate
  • I have included sufficient information for the team to reproduce and understand the issue
@huyannb huyannb added the bug Something isn't working label Apr 27, 2025
@axtgr
Copy link

axtgr commented Apr 27, 2025

Yep, it looks like dynamic agents aren't in the release at all.

@thomaslaberge
Copy link
Contributor

You probably need the alpha versions look on npm to get the latest alpha

No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants