Skip to main content

The “Amalthea” Pattern

When using StateBase with OpenAI, we recommend a specific prompting pattern to maximize reliability: Context Injection. Instead of sending the raw chat history array to OpenAI, you let StateBase curate the context.

Code Example

Why this works better?

  1. Token Efficiency: You don’t send 50 turns of history. You send a summarized state + 5 relevant turns.
  2. Accuracy: “Memories” (long-term facts) are injected explicitly, preventing the model from having to “search” its context window.
  3. Cost: Significantly reduces input token costs for long-running sessions.