Context Management¶
Keep the context small and use @effect context clear to reset between runs.
Example¶
This example:
- Gets 50 books and then summarizes them.
- Stores the summary in a variable called
summaryfor later use. - Clears the context and gets 50 more books
- Summarizes the new books
- Then we contrast the new summary with the previous summary stored in the
summaryvariable.
// file:context_management_example.mg
@state summary = ""
<<
You are a helpful assistant.
I've loaded 50 books into your context so
your context is quite large now.
Give a summary of the books.
Store the summary in a variable called "summary" for later use.
>>
@effect run
// If we load another 50 books, the context will be even larger and may cause issues with token limits.
// If we have a second mdx script we would lose any state from the first script.
// Use @effect context clear to reset the context while retaining the `summary` variable.
@effect context clear
// All variables are retained
<<
Load 50 more books and summarize.
Contrast with Previous Summary: ${summary}
>>
@effect run