Skip to content

feat(operations): pre-turn ContextProvider injection seam (ADR-0100)#1886

Merged
ohdearquant merged 4 commits into
mainfrom
feat/context-provider-seam
Jul 8, 2026
Merged

feat(operations): pre-turn ContextProvider injection seam (ADR-0100)#1886
ohdearquant merged 4 commits into
mainfrom
feat/context-provider-seam

Conversation

@ohdearquant

Copy link
Copy Markdown
Owner

feat(operations): pre-turn ContextProvider injection seam (ADR-0100)

Adds the pre-turn context injection seam: a ContextProvider protocol + ContextProviderRegistry on Branch, folded into the system-guidance render in _prepare.py. Providers run once per turn before prompt assembly; their blocks render into the system message for that turn only and are cleared afterward — the message record is never polluted.

What's in here

  • lionagi/protocols/context_providers.pyContextProvider protocol, ProviderReport (per-provider fired flag + token counts), ContextProviderRegistry with a total token budget and per-provider error containment (a raising provider is skipped and reported, never breaks the turn).
  • Branch.providers property backed by private attrs; zero cost when unused.
  • _prepare.py_build_instruction() extracted; injection folds as system.rendered + injected + guidance. Prebuilt ins= threading avoids double-applying context (create_instruction mutates an already-built Instruction in place).
  • chat.py / run.py — providers applied before prepare; per-turn slot cleared in finally.
  • docs/adrs/ADR-0100-context-injection-providers.md.
  • 17 tests (registry budget/containment, fold rendering, slot lifecycle, systemless-branch behavior).

Notes for review

  • Injection only renders when the branch has a system message — preserves the existing guidance scoping in _prepare.py rather than inventing a new system-message-creation path.
  • No provider implementations ship here; this is the seam only. First consumer lands separately.

🤖 Generated with Claude Code

Adds the seam-only PR 1 from the signed injection design: an ordered
ContextProvider registry on Branch, a per-turn injection slot read by
the chat guidance fold, and budget/failure containment. Pure lionagi,
no khive dependency.

- lionagi/protocols/context_providers.py: ContextProvider protocol,
  ProviderReport, ContextProviderRegistry (budget enforcement drops
  lowest-priority providers first; provider exceptions are contained
  and reported, never raised).
- Branch.providers: lazily-created registry (manager-property pattern
  mirroring msgs/acts/mdls/memory); zero-cost when unused.
- operations/chat/_prepare.py: extracts _build_instruction so the
  Middle can build the Instruction once and reuse it for both provider
  gather and prepare (avoids double-applying context updates); extends
  the guidance fold to system.rendered + injected blocks + guidance;
  adds _apply_context_providers helper.
- operations/chat/chat.py and operations/run/run.py: gather providers
  before _prepare_run_kwargs, clear the slot right after. Injected
  text never enters the durable message record.
- docs/adrs/ADR-0100-context-injection-providers.md: the public
  contract, copied verbatim from the signed design workspace.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
lion-studio Ignored Ignored Preview Jul 8, 2026 9:08pm

Request Review

…eport

Providers render into the system-guidance fold; a branch with no system
message has no render target. Previously providers were still gathered
(spending retrieval + tokens) and their output silently dropped, with the
ProviderReport discarded on every turn path. Now: systemless turns skip
gathering entirely and record every registered provider as skipped; all
turns expose the report via branch.last_context_report.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ohdearquant ohdearquant enabled auto-merge (squash) July 8, 2026 19:34

@oceanwaves630 oceanwaves630 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved per fleet merge flow v2 (design signed at comm gate; codex R2 APPROVE; R1 observable-report fix aligns with the signed rider).

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.

2 participants