K² Agent Context Demo

K² turns private knowledge into cited context for agents

The same source-role-separated context pattern as the Java case study, now applied to Angular forms-signals. K² routes broad and focused tasks to the right guide family before the coding agent edits TypeScript.

One request, fully grounded

Same external coding agent. Better context before the edit.

Developer promptWhich guide rules, source files, and tests should I use before adding an includeDisabled opt-in to compat extractValue?
What K² adds before the edit

The context package tells the agent which guide family and source pair to use.

Follow this guideforms-signals-core-patch-boundary.md (CF-ANGULAR-CORE-000)

Routed by strong_core intent. Constrains edit boundary and forbidden paths.

Use these docsAngular forms-signals docs at the indexed ref

Versioned docs slice. Pinned to angular/angular@9a7dedced6.

Mirror this sourcepackages/forms/signals/compat/src/api/extract.ts

Canonical source neighbor for compat-class extractions.

Extend this specextract_value.spec.ts

Focused spec. Adds default-exclusion and opt-in inclusion regression coverage.

Protect this behaviorNo docs or guide-page edits

Forbidden paths enforced by the patch plan and verified by the scorecard.

The agent still searches and inspects code. K² adds the routed guide, version-pinned docs, source anchor, spec anchor, and review constraint as cited context before the edit.
Patch outcomeAdded the includeDisabled opt-in and extended the focused compat spec.
  • Added includeDisabled to ExtractFilter
  • Inserted disabled-skip guard in visitFieldTree
  • Extended extract_value.spec.ts
AcceptedRubric score 1.00 • CF-ANGULAR-CORE-000
The core insight: source-role-separated context

Coding agents need to know whether retrieved text is a rule, an API contract, implementation precedent, or a spec expectation. K² preserves that role through collections, metadata filters, named agents, and citations instead of flattening every source into one undifferentiated prompt.

Guides set constraintsConfluence guardrails, review rules, edit boundaries, and team conventions.
Docs set API contractsVersion-pinned public or private documentation for framework behavior.
Code shows precedentModules, packages, classes, decorators, and neighboring implementation patterns.
Tests define acceptanceFocused specs and reviewable verification commands before a patch is claimed.
Source-role-separated context architecture

K² keeps guides, docs, code, and tests separated, asks bounded agents in a declared order, and lets a Knowledge Feed promote repeated source findings back into durable guidance.

K² coding context architectureCustomer corporaGuidesDocsCodeTestsNamed K² agentsGuide AgentDocs AgentCode AgentTests AgentArchitect agentGuidesDocsCode + testsPipeline + MCPPipeline SpecMCP serverCoding agentKnowledge Feed: recurring code findings become guide material
How the context reaches the agent

Private knowledge becomes a cited context package before the edit.

Guides, docs, source, and tests stay separated through retrieval, then K² assembles the relevant pieces into a cited package the coding agent can use before it changes TypeScript code.

Customer knowledgeGuides, docs, code, tests
K² platformCollections, Agents, Feed, Pipeline
MCP serverScoped evidence with citations
Coding agentPlans, edits, and explains
TypeScript patchFocused spec and review trail
Two ways to act on the demo

Developers need a short reproducible setup. Enterprise buyers need a controlled pilot against their current coding-agent workflow. The same architecture supports both paths.

Pilot ask

The customer-facing claim should be earned on customer assets. Use this public benchmark to scope a bounded replication, not as a forecast for a financial TypeScript application.

Enterprise path

Run the same workflow on customer assets.

  • Pick one representative Angular package and one Confluence page tree of forms or state conventions.
  • Freeze 10-25 real feature-development tasks before the pilot run.
  • Run the same coding agent, for example Codex or Claude Code, with and without K² retrieval.
  • Score accepted patches, review rework, focused tests, token use, wall-clock time, and retrieval cost.
Design partners wanted

Validate on customer code before making any customer-specific claim.

  • This is a public benchmark and demo bundle, not a named customer replication.
  • Design partners should freeze tasks, expected files, guide checks, and scorer logic before indexing.
  • Publish customer-approved relevance findings, even if the customer name remains anonymized.

Add an includeDisabled opt-in to Angular compat extractValue

The coding agent should identify the right guide family, version-pinned docs, source neighbor, and the focused spec before editing TypeScript.

Collections
Agents
Orchestration
Coding-agent output
Select a step or node to inspect how evidence moves from K² into the coding agent.100-task v2 routing run: K² wins or ties 10 / 12 classes
Benchmark evidence: K² wins broadly on Angular forms-signals

On the v2 routing run, K² MCP leads on accepted patches across 12 task classes with a higher mean rubric score and lower agent-token spend than either Context7 public-docs MCP or a local guide dump.

63 / 100K² MCP accepted patches
47 / 100local guide dump accepted patches
46 / 100Context7 public-docs MCP accepted patches
+16 ptsK² lift over the next best arm

K² mean rubric score 0.949 vs Context7 0.914 vs local guide dump 0.923. Mean guide-guardrail score 0.956 for K², up from 0.680 on the prior routing run.

Token math is agent-side: retrieved snippets count once they enter the coding-agent prompt, but K² platform retrieval, ingestion, storage, and subscription costs are reported separately below. Do not quote this as a broad Context7 ranking or expected customer outcome.

Token economics

Same 100-task v2 routing run, agent-side. K² uses ~46% fewer mean agent tokens than Context7 and is ~2.5x more efficient per accepted patch.

−45.6%Tokens per attempted task vs Context73.12M → 1.70M mean prompt + completion tokens (K² vs Context7).
−60.3%Tokens per accepted patch vs Context76.78M → 2.69M tokens per accepted patch (K² vs Context7).
−55.7%Tokens per accepted patch vs local-dump6.09M → 2.69M tokens per accepted patch (K² vs local guide dump).

Token efficiency tracks accepted work, not only attempted work. The headline efficiency comes from K² producing 63/100 accepted patches versus 46/100 for Context7 and 47/100 for the local guide dump at lower per-task cost.

Methodology and ablation

K² retrieves guide rules and the rubric rewards guide compliance, so the table reports both the accepted-patch count and the mean rubric score. The per-class breakdown below shows where the lift comes from.

Scoring rubric

ComponentWeight
Expected files/modules touched30%
Required behavior or diff-pattern checks25%
Guide guardrail compliance (citation + forbidden paths)20%
Diff present and well-formed10%
Verification (focused tests, type-check, parse)10%
Review scope and safety5%

Accepted patches and mean score by arm

ArmMean scoreAccepted
K² MCPAngular guides, source, tests, and version-pinned docs through K² with intent-routed retrieval.0.949 mean63 / 100
Local guide dumpAll nine guides concatenated and pasted into the agent prompt before each task.0.923 mean47 / 100
Context7 public-docs MCPPublic Angular documentation through Context7, without private guide/source/test corpora.0.914 mean46 / 100

Per-class accepted patches

ClassContext7Local
validation_rule18/1818/1818/18
state_rule8/85/85/8
field_state8/141/141/14
compat_api6/124/126/12
structure_api4/74/73/7
validation_infrastructure4/83/85/8
directive_integration3/122/121/12
control_api3/30/30/3
utility3/51/51/5
metadata_rule3/55/54/5
schema_internals2/52/52/5
webmcp_integration1/31/31/3

Cost model

  • Agent-token numbers count prompt and completion tokens captured by the benchmark runner. Retrieved K² snippets are included once they enter the agent prompt.
  • K² uses about 46% fewer mean agent tokens than Context7 and about 41% fewer than the local guide dump on this 100-task run.
  • Per accepted patch, K² is about 2.52x more token-efficient than Context7 and 2.26x more efficient than the local guide dump.
  • K² platform cost is not hidden in the token-savings number. It includes ingestion, retrieval queries, storage, and subscription.
  • Illustrative benchmark-scale platform allocation: Pro tier at $249/month for this demo corpus and run.
  • If accepted patches are the customer-relevant outcome because guide violations create review rework, K² platform allocation is $249 / 63 ≈ $3.95 per accepted patch before model-token cost.
  • At Claude Sonnet-style input pricing around $3 per million tokens, the 4.09M agent-token savings per accepted patch versus Context7 is about $12.27, roughly 3.1x the benchmark-scale K² platform allocation.
  • These numbers do not include developer time. One avoided review or re-prompt hour at a $150 loaded engineering cost dwarfs the token and platform costs combined.

Authorship and freeze disclosure

The public artifact does not independently prove that task authors, guide authors, and scorer authors were blind to K² outputs before freezing. The defensible public claim is therefore narrower: K² improved this guide-retrieval-heavy benchmark across 12 Angular forms-signals task classes, and customer-specific claims require a frozen customer replication before indexing or running any arm.

Reproducibility statement

Task definitions, scorer configurations, prompt templates, selected raw responses, patch artifacts, and demo asset manifests are published in the repository. An external reviewer can rerun the public benchmark with the same coding-agent model, a K² API key, and the published bundle; customer-specific claims still require customer-frozen tasks and customer-owned corpora.

2 filessource + spec files changed in accepted patch
1 opt-in flagincludeDisabled on ExtractFilter
CF-ANGULAR-CORE-000guide cited by the patch
K² MCParm: codex_with_k2_mcp

Local guide-dump patch excerpt

patch.diff
diff --git a/packages/forms/signals/compat/src/api/extract.ts b/packages/forms/signals/compat/src/api/extract.ts@@ -51,6 +51,12 @@ export interface ExtractFilter {   readonly dirty?: boolean;   readonly touched?: boolean;   readonly enabled?: boolean;+  /**+   * Whether disabled fields are included in the extracted value.+   *+   * Disabled fields are excluded by default to match the compat extraction behavior.+   */+  readonly includeDisabled?: boolean; } @@ -97,6 +103,10 @@ function visitFieldTree(   const state = field();   const value = state.value(); +  if (state.disabled() && filter?.includeDisabled !== true && filter?.enabled !== false) {+    return undefined;+  }+   const matchingChildren = extractChildren(field, value, filter); answer style:Generated from a flat guide-dump prompt; no per-task routing intent surfaced.

K² accepted production change excerpt

patch.diff
diff --git a/packages/forms/signals/compat/src/api/extract.ts b/packages/forms/signals/compat/src/api/extract.ts@@ -51,6 +51,7 @@ export interface ExtractFilter {   readonly dirty?: boolean;   readonly touched?: boolean;   readonly enabled?: boolean;+  readonly includeDisabled?: boolean; } @@ -74,6 +75,7 @@ export function extractValue<T>(field: FieldTree<T>): RawValue<T>;  *  * @param field The field tree to extract the value from.  * @param filter Criteria to include only fields matching certain state (dirty, touched, enabled).+ *   Set `includeDisabled` to `true` to include disabled controls in the extracted value.  * @returns A partial value containing only the fields matching the filter, or `undefined` if none match. @@ -96,6 +98,11 @@ function visitFieldTree( ): RawValue<unknown> | DeepPartial<RawValue<unknown>> {   const state = field();   const value = state.value();+  const includeDisabled = filter?.includeDisabled ?? false;++  if (!includeDisabled && filter?.enabled === undefined && state.disabled()) {+    return undefined;+  }

K² spec, scorecard, and citations

ts + scorecard
diff --git a/packages/forms/signals/test/node/compat/extract_value.spec.ts b/packages/forms/signals/test/node/compat/extract_value.spec.ts@@ -84,6 +84,24 @@ describe('extractValue', () => {     });   }); +  it('should exclude disabled compat controls by default and include them when requested', () => {+    const lastNameControl = new FormControl({value: 'Doe', disabled: true});+    const model = {+      firstName: 'John',+      lastName: lastNameControl,+    };+    const f = compatForm(signal(model), {injector});++    expect(extractValue(f)).toEqual({+      firstName: 'John',+    });++    expect(extractValue(f, {includeDisabled: true})).toEqual({+      firstName: 'John',+      lastName: 'Doe',+    });+  }); scorecard:arm: codex_with_k2_mcpguide_cited: CF-ANGULAR-CORE-000required_diff_pattern_score: 1.00guide_guardrail_score: 1.00expected_file_coverage: 1.00accepted: true sources cited:repo://angular/angular@9a7dedced6/packages/forms/signals/compat/src/api/extract.tsrepo://angular/angular@9a7dedced6/packages/forms/signals/test/node/compat/extract_value.spec.tsgenerated://guides/angular/forms-signals-core-patch-boundary.md

Local-dump answer excerpt

answer.md
Changes:
- Added includeDisabled?: boolean to ExtractFilter with a doc comment.
- Inserted a disabled-skip guard in visitFieldTree that respects existing enabled filtering.
- Added a focused spec that exercises both default exclusion and opt-in inclusion of a disabled compat control.

Tests:
- Attempted pnpm bazel test //packages/forms/signals/test/node:test --test_filter=extractValue
- Result: bazel runner not available in this environment.

Remaining uncertainty:
Runtime verification was not executed because Bazel was unavailable.

K²-assisted answer excerpt

answer.md
Implemented the compat extract opt-in for disabled controls inside
the forms-signals core boundary.

What changed:
- Added includeDisabled?: boolean to ExtractFilter and documented it on extractValue.
- Updated visitFieldTree to skip disabled nodes by default while preserving explicit enabled filtering.
- Added a focused regression spec covering both default exclusion and the includeDisabled: true override.

Sources consulted:
- repo://angular/angular@9a7dedced6/packages/forms/signals/compat/src/api/extract.ts
- repo://angular/angular@9a7dedced6/packages/forms/signals/test/node/compat/extract_value.spec.ts
- generated://guides/angular/forms-signals-core-patch-boundary.md (CF-ANGULAR-CORE-000)

Guide compliance:
Edits stayed inside packages/forms/signals; no docs/guide pages were touched.