feat(templates): add conversation history persistence to HTTP agent templates#794
Open
aidandaly24 wants to merge 1 commit intoaws:mainfrom
Open
feat(templates): add conversation history persistence to HTTP agent templates#794aidandaly24 wants to merge 1 commit intoaws:mainfrom
aidandaly24 wants to merge 1 commit intoaws:mainfrom
Conversation
…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.
Contributor
Package TarballHow to installnpm install https://github.com/aws/agentcore-cli/releases/download/pr-794-tarball/aws-agentcore-0.7.1.tgz |
notgitika
requested changes
Apr 11, 2026
Contributor
notgitika
left a comment
There was a problem hiding this comment.
2 comments but LGTM otherwise
| get_or_create_agent = agent_factory() | ||
| {{else}} | ||
| _agent = None | ||
| _agents = {} |
Contributor
There was a problem hiding this comment.
this dict grows unbounded and becomes heavy, every new session_id will add an Agent instance (with its full message history) that's never evicted. same applies to _sessions in the OpenAI template.
ADK and LangGraph don't have this issue since they use a single service/checkpointer instance.
I'm fine with this for a starter template but should we at least add a comment about this? We can also try to improve this by adding an LRU cache evictor? Is that overkill? 😓 Your call
Comment on lines
75
to
80
| agent = Agent( | ||
| name="{{ name }}", | ||
| model="gpt-4.1", | ||
| mcp_servers=active_servers, | ||
| tools=[add_numbers] | ||
| ) |
Contributor
There was a problem hiding this comment.
you added instructions everywhere else but seems like you missed it here.
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.