Skip to content
New issue

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

By clicking “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? Sign in to your account

feat: allow max context length #2710

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ParkerSm1th
Copy link

Summary

  • Added the ability to optionally pass in maxContextLength to Agent

This is a feature that existed in LangChain + LangSmith workflow, allowing for a sticky systemMessage (instructions in Mastra terms). Adding this allows for devs to utilize this without having to self implement

Tests Added

  • Added unit tests

Copy link

codesandbox bot commented Mar 3, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

changeset-bot bot commented Mar 3, 2025

🦋 Changeset detected

Latest commit: 93c3df4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 46 packages
Name Type
@mastra/core Patch
mastra Patch
@mastra/deployer Patch
@mastra/evals Patch
@mastra/loggers Patch
@mastra/mcp Patch
@mastra/memory Patch
@mastra/rag Patch
@mastra/deployer-cloudflare Patch
@mastra/deployer-netlify Patch
@mastra/deployer-vercel Patch
@mastra/astra Patch
@mastra/chroma Patch
@mastra/pg Patch
@mastra/pinecone Patch
@mastra/qdrant Patch
@mastra/upstash Patch
@mastra/vectorize Patch
@mastra/speech-azure Patch
@mastra/speech-deepgram Patch
@mastra/speech-elevenlabs Patch
@mastra/speech-google Patch
@mastra/speech-ibm Patch
@mastra/speech-murf Patch
@mastra/speech-openai Patch
@mastra/speech-playai Patch
@mastra/speech-replicate Patch
@mastra/speech-speechify Patch
@mastra/voice-deepgram Patch
@mastra/voice-elevenlabs Patch
@mastra/voice-google Patch
@mastra/voice-murf Patch
@mastra/voice-openai Patch
@mastra/voice-playai Patch
@mastra/voice-speechify Patch
@mastra/client-js Patch
@mastra/composio Patch
@mastra/firecrawl Patch
@mastra/github Patch
@mastra/ragie Patch
@mastra/stabilityai Patch
mastra-ai-sdk-use-chat-example Patch
memory-todo-agent Patch
voice-agent Patch
insert-embedding-in-libsql Patch
insert-embedding-in-chroma Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 3, 2025

@parkersm1th-magical is attempting to deploy a commit to the Mastra Team on Vercel.

A member of the Team first needs to authorize it.

@ParkerSm1th ParkerSm1th changed the title Allow max context length feat: allow max context length Mar 3, 2025
Copy link

promptless bot commented Mar 3, 2025

📝 Documentation updates detected! You can review documentation updates here

@ParkerSm1th ParkerSm1th force-pushed the parker/allow-content-system-message branch from 897b605 to 93c3df4 Compare March 3, 2025 01:10
@dennis-magical
Copy link

This would be super helpful for us

@wardpeet
Copy link
Contributor

wardpeet commented Mar 3, 2025

I'm not sure we should add it. Shouldn't we throw an error instead that the message got to big? If we cut the message from the start, we might not get the expected result.

@abhiaiyer91
Copy link
Contributor

Ah i understand now, this trims the context between System (instructions) and user prompt.

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok i misread it, it's just context being sliced. Let's remove the dynamic function.

Thank you for contributing!

Comment on lines +111 to +117
__updateMaxContextLength(newMaxContextLength: number) {
this.maxContextLength = newMaxContextLength;
this.logger.debug(`[Agents:${this.name}] Max context length updated.`, {
model: this.model,
name: this.name,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove dynamic updatinhg of max length for now

Suggested change
__updateMaxContextLength(newMaxContextLength: number) {
this.maxContextLength = newMaxContextLength;
this.logger.debug(`[Agents:${this.name}] Max context length updated.`, {
model: this.model,
name: this.name,
});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants