Skip to content

feat(models): type exchange info as Ask/PostExchangeInfo - #65

Merged
david-debest merged 1 commit into
mainfrom
45-feat/typed-exchange-info
Oct 1, 2026
Merged

david-debest merged 1 commit into
mainfrom
45-feat/typed-exchange-info

Conversation

@david-debest

Copy link
Copy Markdown
Contributor

Closes #45

Why

The KE OpenAPI spec reports exchanges with ANSWER KIs as AskExchangeInfo (with the answered bindingSet) and exchanges with REACT KIs as PostExchangeInfo (with argumentBindingSet / resultBindingSet). We parsed both into a flat ExchangeInfo and dropped the bindings.

What

  • ke/models.py: AskExchangeInfo and PostExchangeInfo subclass ExchangeInfo (so existing isinstance(info, ExchangeInfo) checks still work). AskResult / PostResult / ExchangeResult.exchange_info are now list[AskExchangeInfo | PostExchangeInfo] (exported as AnyExchangeInfo).

  • The subtype is picked by a pydantic callable discriminator:

    1. knowledgeInteractionType (AnswerKnowledgeInteraction / ReactKnowledgeInteraction). The KE only sends this after 1.5.0 (TNO/knowledge-engine@0ea958b), and from then on one ASK/POST result can mix both kinds because the reasoner combines KIs.
    2. Otherwise inferred from the binding set fields present (KE ≤ 1.5.0, e.g. the 1.3.2 used in examples/compose.yaml).
    3. Otherwise the result kind: ASK → AskExchangeInfo, POST → PostExchangeInfo.

    An unknown knowledgeInteractionType raises a ValidationError.

  • Exchange info bindings stay raw dict[str, str]: they follow the other KI's graph pattern, not the local binding model.

  • FakeClient returns AskExchangeInfo (mocked bindings) for ASK and PostExchangeInfo (posted arguments + mocked results) for POST.

  • README, CONTEXT.md and example 03 are updated.

Testing

  • tests/test_client.py: parsing the ≤ 1.5.0 shape, the newer mixed discriminated shape, the POST fallback without binding sets, and rejection of unknown types.
  • tests/test_ask_and_post.py: the subtypes and bindings from the FakeClient.
  • uv run pytest tests/, ruff check, ruff format --check pass; no new pyright errors.

The KE OpenAPI spec reports exchanges with ANSWER KIs as AskExchangeInfo
(with the answered bindings) and with REACT KIs as PostExchangeInfo (with
argument and result bindings), but we parsed both into a flat ExchangeInfo
and dropped the bindings.

Since KE 1.5.0 entries carry a knowledgeInteractionType discriminator and
one ASK/POST result may mix both kinds. Older KEs omit it, so the subtype
is inferred from the binding set fields, falling back to the result kind.
Exchange info bindings stay raw: they follow the other KI's graph pattern.

Closes #45

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@david-debest david-debest self-assigned this Oct 1, 2026
@david-debest
david-debest merged commit f771795 into main Oct 1, 2026
3 checks passed
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.

Implement PostExchangeInfo and AskExchangeInfo as per KE OpenAPI spec

1 participant