Skip to content

feat(api): agent({ runtime: 'gmi' }) routing, the remaining gmi() surface and its guide - #159

Merged
jddunn merged 3 commits into
masterfrom
feat/gmi-runtime-routing
Oct 8, 2026
Merged

jddunn merged 3 commits into
masterfrom
feat/gmi-runtime-routing

Conversation

@jddunn

@jddunn jddunn commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Summary

agent({ runtime: 'gmi' }) builds the agent with gmi() (#135), so every session of the agent is served by a Generalized Mind Instance built in process from the agent's options. agent() without runtime, or with runtime: 'legacy', keeps its current path.

The branch lands in steps:

  • Routing, exports and the remaining end-to-end cases. agent() checks runtime before anything else, so an agent on the GMI path gets the GMI path's construction checks and diagnostics, not the legacy helper's. gmi, createGmi, resolveCognition, personaFromAgentOptions, createAgentCognitiveMemory and the types GmiOptions, GmiHandle, CognitionProfile, CognitionConfig, CognitionInputs, ResolvedCognition, MetapromptPreset, AgentCognitiveMemory and AgentCognitiveMemoryOptions are exported from @framers/agentos/api and from the package root; the package root also exports AgentSessionOptions.
  • Fixes for the findings of the reviews of feat(runtime): completion gateway and the GMI step contract #129 and feat(api): agent() sessions served by a GMI with runtime: 'gmi' #135, one test-first pair each.
  • The guide (docs/GMI.md, docs/API_PATHS.md, README.md) and the release notes in this description.

Linked issues

Follows #129 and #135.

Type of change

  • Bug fix
  • Feature
  • Performance
  • Documentation
  • Refactor
  • Tests
  • Build or CI

How this was verified

CI (Test & Lint). src/api/__tests__/gmi-runtime.session.test.ts, gmi-runtime.fallback.test.ts and gmi-runtime.memory.test.ts run agent({ runtime: 'gmi' }) end to end over the real provider manager, completion gateway, GMI, prompt engine, tool orchestrator, cognitive memory and session store, with the OpenAI and Anthropic provider classes stubbed at their module boundary. The existing agent(), streamText and GMI tests run unchanged. The first commit adds the end-to-end cases and fails; the routing commit turns them green.

Migration notes

None. runtime: 'gmi' is opt-in; agent() without it behaves as before.

Checklist

  • Tests cover the changed behavior.
  • Docs are updated.
  • The title follows Conventional Commits, with ! before the colon for a change that breaks users (feat!: or feat(api)!:).
  • No secrets or private data are included.
  • Every automated review thread is settled (how).
  • I have read this change and can explain every line.

Summary by Sourcery

Add opt-in GMI routing to agent() with the remaining GMI surface, provider and memory behavior, public exports, and end-to-end coverage.

New Features:

  • Route agent({ runtime: 'gmi' }) through an in-process Generalized Mind Instance while preserving the existing default and legacy agent paths.
  • Expose GMI construction, cognition, persona, and cognitive-memory APIs and types from the API entry point and package root.

Bug Fixes:

  • Preserve provider fallback behavior across tool-call steps, prompt rebuilding, streaming failures, and subsequent turns.
  • Ensure agent-level generation options are not overwritten by undefined per-send values.

Enhancements:

  • Build GMI cognition and memory directly from agent options, including configured embedding providers and memory-provider compatibility diagnostics.

Tests:

  • Add end-to-end coverage for GMI agent sessions, provider fallback, partial failures, tool execution, streaming, and cognitive memory.

Summary by CodeRabbit

  • New Features
    • Added public access to the GMI runtime and its cognition and cognitive-memory APIs.
    • The agent() API can now use the GMI runtime through a runtime option, allowing you to create agents through the existing entry point.
    • Added public access to session options and helpers for configuring cognition, personas, and cognitive memory.

…mi' })

The remaining end-to-end cases of the GMI path, written against agent()
rather than gmi(): a primary that fails to start, a fallback hop with a
smaller context window, a provider change between the steps of one turn,
a failed step after a tool ran, a stream that breaks after its first
delta, the return to the primary on the next turn, cognitive memory
recall, cognitive memory beside a memoryProvider, embeddings for an
Anthropic chat model, and a memory with no embedding source failing on
the first call. A routing case checks that runtime: 'gmi' builds the
agent on the GMI path and runtime: 'legacy' keeps the helper.

agent() does not route on runtime yet, so these fail.
@jddunn
jddunn requested a review from Victor-Evogor as a code owner October 8, 2026 15:56
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai

sourcery-ai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Sorry @jddunn, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 14 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: framerslab/agentos/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 4eba09ad-705f-4db2-bb15-5d62fb55460d
📥 Commits

Reviewing files that changed from the base of the PR and between 92e1f4a and e95f64c.

📒 Files selected for processing (2)
  • src/api/__tests__/gmi-runtime.memory.test.ts
  • src/api/__tests__/helpers/stubProviders.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The agent() API now routes GMI runtime requests through gmi(). The API barrels export GMI-related APIs and types. Tests cover runtime diagnostics, provider fallback, and cognitive memory behavior.

Changes

GMI runtime

Layer / File(s) Summary
Agent runtime routing and API exports
src/api/agent.ts, src/api/index.ts, src/index.ts
agent() delegates to gmi() when runtime is 'gmi'. A helper copies only defined per-send generation overrides. The API barrels export GMI, cognition, persona, and cognitive-memory APIs and related types.
Session and runtime diagnostics
src/api/__tests__/gmi-runtime.session.test.ts
Session tests now construct GMI agents through agent({ runtime: 'gmi' }). Diagnostic tests check the messages for GMI and legacy runtime configurations.
Provider fallback test coverage
src/api/__tests__/gmi-runtime.fallback.test.ts
Tests cover provider fallback after initialization failure, rebuilding prompts for a smaller context window, tool-call history conversion, exhausted fallback, partial streaming errors, and provider selection across steps and turns.
Cognitive memory test coverage
src/api/__tests__/gmi-runtime.memory.test.ts, src/api/__tests__/helpers/stubProviders.ts
Tests cover recalled content, memoryProvider behavior, embedding with an OpenAI provider and Anthropic chat, and rejection when no embedding source is configured. Provider test scripts record embedding inputs.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Merge Risk: ⚪ Minimal · up to e95f6

The reviewed changes strengthen GMI memory test coverage, and no actionable merge-blocking risk is identified; normal checks are sufficient.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 7 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise, specific, and accurately summarizes GMI routing, API changes, and documentation work. It follows Conventional Commits format.
Description check ✅ Passed The description includes the required summary, linked issues, change type, verification details, migration notes, and checklist. The unchecked documentation item conflicts with the stated documentatio…
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR makes agent({ runtime: 'gmi' }) construct and serve sessions through the GMI runtime while retaining the legacy path by default, with end-to-end tests covering routing diagnostics, provider fallback and failure semantics, tool/stream behavior, and cognitive-memory integration.

File-Level Changes

Change Details Files
Route opted-in agents through the in-process GMI runtime while preserving legacy behavior by default.
  • Select the GMI path before legacy construction when runtime: 'gmi' is provided.
  • Keep omitted or runtime: 'legacy' agents on the existing helper path.
  • Verify that GMI-specific diagnostics and legacy diagnostics remain distinct.
src/api/__tests__/gmi-runtime.session.test.ts
Add end-to-end coverage for GMI provider fallback, tool execution, streaming failures, and session continuity.
  • Exercise fallback on initialization and mid-turn provider failure, including prompt rebuilding for smaller context windows.
  • Verify cross-provider tool-call history translation and partial session state when a turn exhausts its chain.
  • Verify streaming returns accumulated text while exposing the terminal error, and that fallback selection persists only within the current turn.
src/api/__tests__/gmi-runtime.fallback.test.ts
Add end-to-end coverage for cognitive memory construction and runtime behavior from agent options.
  • Verify full cognition embeds and recalls facts across cleared sessions using the configured embedding provider.
  • Verify memoryProvider is superseded by the cognitive-memory bridge while observation still runs and emits the appropriate warning.
  • Verify chat and embedding providers can differ, and missing embedding configuration fails on first use before any model request.
src/api/__tests__/gmi-runtime.memory.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

test(api): cover agent GMI routing, fallback, and memory

🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Add end-to-end tests for GMI fallback, tool history, streaming errors, and session recovery.
• Verify cognitive memory recall, embedding selection, and memory-provider coexistence.
• Assert that agent() selects GMI diagnostics while runtime: 'legacy' retains helper
 diagnostics.
Diagram

graph TD
  Tests["Integration tests"] --> Agent["agent factory"] --> GMI["GMI sessions"] --> Gateway["Completion gateway"] --> Stubs["Provider stubs"]
  Agent --> Legacy["Legacy helper"]
  GMI --> Memory["Cognitive memory"]
Loading
High-Level Assessment

Keep the provider-boundary stubs: they make fallback and embedding failures deterministic without replacing the runtime components being tested. This diff adds tests only; agent() does not yet route on runtime, so the GMI-path cases require the planned implementation commit before they can pass.

Files changed (3) +186 / -0

Tests (3) +186 / -0
gmi-runtime.fallback.test.tsExercise fallback and partial-failure behavior through agent() +97/-0

Exercise fallback and partial-failure behavior through agent()

• Adds six end-to-end cases for provider initialization failure, smaller fallback context windows, tool-history translation across providers, exhausted fallback chains, interrupted streams, and provider selection across turns. Provider classes are stubbed while the GMI runtime components remain real.

src/api/tests/gmi-runtime.fallback.test.ts

gmi-runtime.memory.test.tsExercise cognitive memory and embedding behavior through agent() +73/-0

Exercise cognitive memory and embedding behavior through agent()

• Adds four cases for recall after session history is cleared, coexistence with memoryProvider hooks, OpenAI embeddings for Anthropic chat, and first-call failure when no embedding source exists.

src/api/tests/gmi-runtime.memory.test.ts

gmi-runtime.session.test.tsAssert runtime-specific agent construction diagnostics +16/-0

Assert runtime-specific agent construction diagnostics

• Adds a routing case expecting 'runtime: 'gmi'' to produce GMI diagnostics and 'runtime: 'legacy'' to retain lightweight-helper diagnostics. The existing GMI session tests are unchanged.

src/api/tests/gmi-runtime.session.test.ts

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. GMI requests still use the legacy agent ✓ Resolved
Description
agent() never checks opts.runtime, so the new routing test calls the lightweight helper even
when it requests 'gmi'. Agents created through that option receive the legacy diagnostics and
execution path, and the new routing and end-to-end tests cannot pass as written.
Code

src/api/tests/gmi-runtime.session.test.ts[346]

+    legacyAgent({ ...base(key()), discovery: { enabled: true }, cognitiveMechanisms: {} });
Evidence
The new test expects GMI diagnostics from agent() with runtime: 'gmi', but agent() begins
constructing the lightweight agent and issuing its diagnostics without branching on runtime.
gmi() is a separate factory.

src/api/tests/gmi-runtime.session.test.ts[341-353]
src/api/agent.ts[786-805]
src/api/gmi.ts[1-5]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`agent({ runtime: 'gmi' })` still constructs the legacy agent, so the new routing and end-to-end tests fail.
## Fix Focus Areas
- src/api/agent.ts[786-805]
- src/api/__tests__/gmi-runtime.session.test.ts[341-354]
## Recommended Fix
Check `runtime` at the start of `agent()` and return the `gmi()` handle for `'gmi'` before running legacy diagnostics or construction; retain the existing path for absent or `'legacy'` values.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Memory test misses failed turn encoding ✓ Resolved
Description
e.embedCalls > 0 counts the embedding probe performed while cognitive memory is built, rather than
specifically checking that the Anthropic chat exchange was encoded. The assertion therefore passes
even if encoding after send('remember tea') never invokes the configured OpenAI embedding
provider.
Code

src/api/tests/gmi-runtime.memory.test.ts[62]

+    expect(e.embedCalls).toBeGreaterThan(0);
Evidence
Memory construction unconditionally calls probeEmbeddingModel, which increments the stub's
embedding-call counter before turn encoding occurs. Actual observation and encoding are a separate
operation, so the assertion cannot distinguish them.

src/api/tests/gmi-runtime.memory.test.ts[55-63]
src/api/runtime/agentCognitiveMemory.ts[217-235]
src/api/runtime/agentCognitiveMemory.ts[261-269]
src/cognition/substrate/CognitiveMemoryBridge.ts[275-289]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The Anthropic-chat memory test counts the construction-time embedding probe as evidence of turn encoding.
## Fix Focus Areas
- src/api/__tests__/gmi-runtime.memory.test.ts[55-63]
## Recommended Fix
Distinguish the initialization probe from embeddings of the sent exchange, for example by recording embedding inputs in the provider stub and asserting that an input contains the turn's text.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

jddunn added 2 commits October 8, 2026 09:01
agent() checks runtime before anything else: with runtime: 'gmi' it
returns gmi(opts), so the agent gets the GMI path's construction checks
and diagnostics, and Agent.session's options (the session's user id)
reach the GMI session. Without runtime, or with runtime: 'legacy', it
keeps the legacy path.

gmi, createGmi, resolveCognition, personaFromAgentOptions and
createAgentCognitiveMemory are exported from @framers/agentos/api and
from the package root, with GmiOptions, GmiHandle, CognitionProfile,
CognitionConfig, CognitionInputs, MetapromptPreset, ResolvedCognition,
AgentCognitiveMemory and AgentCognitiveMemoryOptions; the package root
also exports AgentSessionOptions.

The session end-to-end tests now build their agents with agent().
…provider

Building cognitive memory now embeds one fixed text through the chosen
provider, so an embedCalls count above zero holds even when memory never
embeds anything afterwards. The provider stub records each text it
embeds, and the two cases look for their own words: the deploy-key fact
for the OpenAI chat model, the user's turn for the Anthropic chat model
whose memory embeds through OpenAI.
@jddunn
jddunn merged commit cf3a637 into master Oct 8, 2026
6 checks passed
@jddunn
jddunn deleted the feat/gmi-runtime-routing branch October 10, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant