feat(intelligence): withIntelligence hook — unify send/receive, fix dropped typed diffs#504
Merged
Conversation
…diffs Unify the three Intelligence send/receive fragments behind one hook. The composed endpoint already returns agentProfileDiffs/capabilities/agentProfile; the SDK now deserializes them instead of dropping them. - withIntelligence(agent, config): observe + deliver only. SENDs a typed RunRecord via the shipped OTLP builders to /v1/otlp; RECEIVEs the certified profile and surfaces promoted profile diffs as proposals() / onProposals. Never auto-applies a diff at runtime (applyProfile is caller-invoked). - CertifiedProfile + pullCertified extended with agentProfileDiffs (typed diff + held-out provenance), capabilities, and the composed agentProfile. - Delete withTangleIntelligence and withCertifiedDelivery; collapse the endpoint env sprawl behind one base URL (baseUrl / TANGLE_INTELLIGENCE_URL) that both send and receive derive from.
…ound-trip - with-intelligence.test.ts: the previously-dropped agentProfileDiffs now round-trip through proposals(); applyProfile == applyAgentProfileDiff; the hook never auto-applies (delivers only the certified prompt surface); a typed RunRecord ships to /v1/otlp carrying target + usage split. - intelligence.test.ts: baseUrl replaces endpoint; export gates on the tenant key; add the exportRunRecord send path. - delivery/capability tests: extend the CertifiedProfile fixtures with the typed diff fields; assert pullCertified deserializes them.
…baseUrl Drop-in and webcode examples now wrap agents with withIntelligence; endpoint config collapses to the single baseUrl. Send gates on the tenant apiKey, so the offline demos pass a demo key to still exercise the export path.
…ase URL Update the canonical API decision table, intelligence-sdk guide, build skill, example READMEs, the go-live archive, and the regenerated typedoc pages. Fix the package-export verifier's expected list. Collapse the last INTELLIGENCE_BASE / INTELLIGENCE_OTLP_ENDPOINT env references to the single TANGLE_INTELLIGENCE_URL. Grep across the repo now shows zero withTangleIntelligence/withCertifiedDelivery.
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.
What
One agent-runtime SDK hook,
withIntelligence, that unifies the three fragmented Intelligence send/receive mechanisms and fixes the dropped typed-diff receive.The Intelligence plane's
GET /v1/profiles/:target/composedalready returns{ agentProfile, agentProfileDiffs, capabilities }, but the old receive path (withCertifiedDelivery/CertifiedProfile/pullCertified) deserialized onlypromptSurface+artifactsand dropped the typedagentProfileDiffs. This PR deserializes what was already on the wire and surfaces it.The hook
RunRecord { runId, traceId, project, target, input, output, outcome:{success?,score?,usage:{inferenceUsd,intelligenceUsd}}, model?, provider?, loopEvents? }serialized through the existing OTLP builders (flatOtelSpan+buildLoopOtelSpans, no second builder) to/v1/otlp. Best-effort / fail-open.CertifiedProfile+pullCertifiedextended withagentProfileDiffs: {diff: AgentProfileDiff, provenance:{version,lift,contentHash,promotedAt}}[],capabilities, andagentProfile. The previously-dropped typed diffs now round-trip.AppliedIntelligence+=proposals,applyProfile(base)(folds viaapplyAgentProfileDifffrom@tangle-network/agent-interface@0.19.0), andrecord(report)to populate the RunRecord. The prompt-onlycomposePrompt(base)convenience is preserved.proposals()/onProposals, andapplyProfileis caller-invoked. This preserves the held-out invariant the plane enforces.Clean replacement (no consumers — delete, not deprecate)
withTangleIntelligenceandwithCertifiedDelivery(and their prompt-only types).withIntelligenceis the one hook. Repo-wide grep shows zero references to the deleted names.baseUrlconfig /TANGLE_INTELLIGENCE_URLenv, from which both send (${base}/v1/otlp) and receive (${base}/v1/profiles/:target/composed) derive. RemovedINTELLIGENCE_OTLP_ENDPOINT, theOTEL_EXPORTER_OTLP_ENDPOINTdual-read, andINTELLIGENCE_BASE. Send now gates on a tenantapiKey(the ingest requires it).Verification
pnpm build(ESM + DTS),pnpm typecheck,pnpm verify:package,pnpm docs:freshness— all green.pnpm test— 1280 passed, 2 skipped (132 files).agentProfileDiffs[]flows through the receive path;proposals()returns them andapplied.applyProfile(base)equalsapplyAgentProfileDiff(base, diff)— the previously-dropped diffs are received.RunRecordships to/v1/otlpcarryingtarget+ the usage split + model.Deferred
The optional
defineAgent.intelligencebinding +improve(seedFrom: applied.proposals)is deferred — it ripples into the held-out improvement loop's proposer contract (a separate subsystem), and proposals are already accessible viaapplied.proposals/wrapped.proposals(), so nothing is blocked.