Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
| if (user !== undefined && ["", "-"].includes(user.trim())) { | ||
| throw new Error(`userId names a loom user or is undefined; ${JSON.stringify(user)} names none`); | ||
| } | ||
| const prefix = (opts.keyPrefix ?? "openai-agents").replace(/^\/+|\/+$/g, ""); |
This branch has not been deployed
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.
Related: #650 (the OpenAI Agents SDK tools this sits next to)
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
The Python and TypeScript SDKs ship
LoomSession, the OpenAI Agents SDK'sSessionover Loom: a run's conversation history lives in Loom, so every process and both SDKs that open the same session for the same user read the same history.Why
The OpenAI Agents SDK keeps a run's conversation history in a
Session(get_items,add_items,pop_item,clear_session); its own implementations are a local SQLite file, Redis and OpenAI's hosted conversations. With Loom's tools (#650) a model keeps long-term memory in Loom, but the history itself stayed in one of those stores; the frameworks page said Loom could not hold it because Loom's conversations are append-only. This PR implements the session over Loom's memory rows, which do support removal, so the history lives in the user's Loom deployment next to their memories. No store, vector database or cache is added.Design (interfaces read from
openai-agents0.24.0 and@openai/agents0.22.0):Sessionprotocol, notSessionABC. The SDK's docstring asks third-party libraries to implement the protocol.LoomSessionhassession_id,session_settingsand the four async methods; the TypeScript classimplements Session(getSessionId,getItems,addItems,popItem,clearSession).memory.setof typeepisodicunder<key_prefix>/<20-digit nanoseconds>-<8 random hex>, its JSON the value. An episodic memory is not embedded, so it is never merged with or judged against another row (checked against a running server: three identical items under three keys answer with no verdict and stay three rows); the timestamp keys sort in the order items were added, and the random suffix keeps two writers apart.memory.bulk_setis not used: a batch folds a value byte-identical to a live row of the same user, and a conversation repeats items.oai-<first 20 hex of sha256 of the compact JSON [user, session id]>(Loom files a long value's chunks by session alone, and a caller chooses its ids; The Python SDK ships a Google ADK memory service #696 found this for ADK). Both SDKs hash the same compact JSON, so a Python and a TypeScriptLoomSessionof the same id and user read the same rows (a test in each pins the same digest).get_itemslists the session's rows (memory.listwithprefix,memory_type="episodic",fields=["memory_key", "value"], paged byoffsetwhiletruncated) and keeps the latestlimit, orsession_settings.limit(resolve_session_limit, as the SDK's own sessions do).pop_itemdeletes and returns the last row;clear_sessiondeletes every row of the session; both usememory.deleteunder the user and session, so another user's or session's history is untouched.user_idunset writes the namespace's shared rows; an empty or-user, an empty session id and an empty key prefix are refused.Scope and risk
SDK-only: two classes in the existing OpenAI Agents modules (no new extra or peer dependency), docs. No server, wire or schema change; episodic memories are covered by erasure like every memory row.
uv.lockandpackage-lock.jsonare unchanged.Compatibility, rollout and rollback
Tests
sdk/python/tests/test_openai_agents.pythroughmake test-sdk-adapter-openai-agents(17 tests, 7 new;mypy --strict): items keep their order across list pages, with a repeated item kept twice, written asepisodicrows of the user and the derived session;get_items(limit),limit=0andsession_settings.limit;pop_itemreturns and removes the latest,Nonewhen empty;clear_sessiondeletes only its own session's rows, not another session's or another user's; the derived session is per user, unambiguous and equal to the TypeScript one; the refusals; a realRunnerwith a scripted model reads the first run's history in the second run and extends it.SDK_ADAPTERS_RESOLUTION=lowest-directon Python 3.11 (openai-agents0.24.0).sdk/typescript/src/integrations/openai-agents.test.ts(4 new, through a realAgentover a fetch stub): the same order, paging, repeats, episodic rows, pop, clear, refusals and the shared digest. The TS SDK's gates:biome check,tsc --noEmit,vitest run(353 passed),check:readme,check:dist(the dist exports test now listsLoomSession).tests/integration/test_sdk_openai_agents_session.pyagainst a local server: items added, read back as written (as episodic rows of the user and session), invisible to another user, popped, limited and cleared. 1 passed withopenai-agentsinstalled; without it the module skips, as in CI's integration jobs.make format lint; the unit tests that name the integrations, the extras, the framework docs, doc links and public copy (990 passed).AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. Checked:
Session,SessionABC,SQLiteSessionandresolve_session_limitinopenai-agents0.24.0 and theSessioninterface in@openai/agents-core, runs through the SDK'sRunner, and the session against a running Loom.I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass (locally the named unit tests; the full suite in CI'spytest unitparts); the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code