feat(templates): add conversation history persistence to HTTP agent templates#794
Open
aidandaly24 wants to merge 2 commits intoaws:mainfrom
Open
feat(templates): add conversation history persistence to HTTP agent templates#794aidandaly24 wants to merge 2 commits intoaws:mainfrom
aidandaly24 wants to merge 2 commits intoaws:mainfrom
Conversation
Contributor
Package TarballHow to installnpm install https://github.com/aws/agentcore-cli/releases/download/pr-794-tarball/aws-agentcore-0.8.0.tgz |
notgitika
requested changes
Apr 11, 2026
Contributor
notgitika
left a comment
There was a problem hiding this comment.
2 comments but LGTM otherwise
…nt templates Each framework's HTTP template now maintains conversation history across invocations within the same session, using that framework's built-in session management mechanism: - Strands: per-session Agent cache keyed by session_id (Agent accumulates messages internally across stream_async calls) - OpenAI Agents: SQLiteSession passed to Runner.run() which automatically loads/saves conversation history per session - Google ADK: module-level InMemorySessionService with get_or_create_session pattern so the Runner accumulates events per session across invocations - LangGraph: module-level InMemorySaver checkpointer with thread_id mapped to session_id, using the add_messages reducer to append new messages Also adds missing system prompts to OpenAI Agents (instructions parameter) and LangGraph (prompt parameter) templates.
… lru_cache Address review feedback: - Add missing instructions= to OpenAI Agents template (non-gateway MCP branch) - Replace unbounded dict caches with @lru_cache(maxsize=128) in Strands and OpenAI Agents templates to prevent memory growth from accumulating one Agent/SQLiteSession per session_id indefinitely
1e4f23a to
ea2f0cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
All four HTTP agent templates (Strands, OpenAI Agents, Google ADK, LangChain/LangGraph) were stateless per-invocation — each call to the agent started with zero conversation context. This meant users couldn't have multi-turn conversations where the agent remembers what was said in previous turns within the same session.
This PR adds conversation history persistence using each framework's built-in session management mechanism:
Agentcache keyed bycontext.session_id. StrandsAgentaccumulates messages internally inself.messagesacrossstream_async()calls, so reusing the same instance per session gives natural multi-turn memory. This also fixes a conversation bleed bug where the previous single global_agentshared history across all sessions/users.SQLiteSession(from the SDK) passed via thesession=parameter onRunner.run(). The session automatically loads prior history before inference and saves new turns after. Uses in-memory SQLite by default (:memory:).InMemorySessionServicewith aget_or_create_session()helper that callsget_session()first and onlycreate_session()if the session doesn't exist (avoidsAlreadyExistsErroron repeat calls). The module-levelRunnershares the same service instance across invocations.InMemorySavercheckpointer withthread_idmapped tocontext.session_id. Theadd_messagesreducer onAgentState.messagesautomatically appends newHumanMessages to the existing conversation from the checkpoint. The graph is recreated per-invocation (to pick up dynamic MCP tools) but the checkpointer is shared, so state persists.Also adds missing system prompts:
instructions="You are a helpful assistant. Use tools when appropriate."to allAgent()constructors (previously had no system prompt at all).prompt="You are a helpful assistant. Use tools when appropriate."tocreate_react_agent().All conversation state is in-memory (best-effort) — it persists across invocations within the same runtime process but resets on cold starts. This is the correct default for starter templates; users can upgrade to durable backends (Strands
FileSessionManager, OAISQLiteSessionwith file path, ADKDatabaseSessionService, LangGraph persistent checkpointers) as needed.Related Issue
Closes #808
Closes #809
Closes #810
Type of Change
Testing
How have you tested the change?
npm run test:unitandnpm run test:integnpm run typechecknpm run lintsrc/assets/, I rannpm run test:update-snapshotsand committed the updated snapshotsEnd-to-end deploy + invoke testing:
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.