Skip to content

feat: Add inference-parser plugin for outbound LLM traffic - #365

Merged
huang195 merged 2 commits into
rossoctl:mainfrom
huang195:feat/inference-parser-plugin
May 5, 2026
Merged

huang195 merged 2 commits into
rossoctl:mainfrom
huang195:feat/inference-parser-plugin

Conversation

@huang195

@huang195 huang195 commented May 4, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds inference-parser plugin that parses outbound OpenAI-compatible LLM requests (/v1/chat/completions, /v1/completions)
  • Populates pctx.Extensions.Inference with model, messages, temperature, max_tokens, stream, and tool names
  • Registers "inference" extension slot in defaultSlots and factory in plugin registry
  • Path-based detection ensures only LLM traffic is parsed (MCP, A2A, and other outbound traffic is unaffected)

Completes the Phase 2 protocol parser triad:

  • Inbound: mcp-parser (MCP JSON-RPC), a2a-parser (A2A JSON-RPC)
  • Outbound: inference-parser (OpenAI REST)

Motivation

Kagenti agents call LLMs (Ollama, vLLM) via the OpenAI-compatible /v1/chat/completions endpoint. This plugin gives the outbound pipeline visibility into inference request content, enabling future downstream plugins for:

  • Prompt guardrails (block PII, enforce content policy, limit prompt size)
  • Audit/observability (log model usage, token patterns)

Pipeline Placement

pipeline:
  outbound:
    plugins:
      - inference-parser   # parse LLM request body
      - token-exchange     # exchange token for LLM audience
      # future: prompt-guardrails (reads "inference" extension slot)

Not added to default pipelines — users opt in via config.

Test plan

  • go test ./plugins/... -run Inference -v — 11 tests pass
  • go test ./... — all authlib tests pass
  • go build ./... — binary builds cleanly
  • End-to-end: configure inference-parser in outbound pipeline, send chat through UI, verify inference-parser model=llama3.1 in logs

Assisted-By: Claude (Anthropic AI) [email protected]

@huang195
huang195 marked this pull request as draft May 4, 2026 20:07
@huang195
huang195 marked this pull request as ready for review May 5, 2026 00:32

@mrsabath mrsabath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review Summary

Well-structured plugin that completes the Phase 2 parser triad (inbound: mcp-parser + a2a-parser, outbound: inference-parser). Follows existing plugin patterns, has good test coverage (11 tests), and correctly uses path-based gating so non-LLM traffic is unaffected. The extension struct design is clean with proper use of pointer types for optional fields.

Suggestions (non-blocking)

  1. Log level — slog.Info("inference-parser", "model", ext.Model) fires on every parsed request. The slog.Debug on the next line already covers the same info with more context. Consider making the Info-level log Debug-level too, to reduce noise in production.

  2. Legacy /v1/completions prompt field — The endpoint uses a prompt string rather than messages[]. Currently it's silently ignored (model and max_tokens are captured, which is useful). Fine for MVP — worth a brief comment or TODO if you plan to support it later.


Areas reviewed: Go code, pipeline architecture, security, tests
Commits: 1, DCO signed-off ✓
CI status: All checks pass

LGTM — clean implementation.

Reviewed with Claude Code

Add the inference-parser plugin that parses outbound OpenAI-compatible
LLM inference requests (/v1/chat/completions, /v1/completions) and
populates pctx.Extensions.Inference for downstream policy plugins
(prompt guardrails, audit/observability).

Extracted fields: model, messages[], temperature, max_tokens, stream,
tool/function names. Path-based detection ensures non-LLM outbound
traffic (MCP calls, other APIs) is not parsed.

Like mcp-parser, it is NOT added to default pipelines — users opt in
via config. This completes the Phase 2 protocol parser triad:
- Inbound: mcp-parser (MCP JSON-RPC), a2a-parser (A2A JSON-RPC)
- Outbound: inference-parser (OpenAI REST)

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@huang195
huang195 force-pushed the feat/inference-parser-plugin branch from a6c13fc to 45fe965 Compare May 5, 2026 00:51
Replace non-existent NeedsResponseBody() with NeedsBody(). Remove
unused context and strconv imports in extproc after rebase.

Signed-off-by: Hai Huang <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@huang195
huang195 merged commit 8c7c3a9 into rossoctl:main May 5, 2026
17 checks passed
@huang195
huang195 deleted the feat/inference-parser-plugin branch May 5, 2026 00:57
boazdavid added a commit to boazdavid/cortex that referenced this pull request Nov 24, 2026
…known, and fix a real regression in the zero-prompt-total gate

Two more findings from clawgenti's re-review:

- The currency fix only gated PluginSpendMicros (basis usd). PluginSpendUnknownMicros
  is "not money", but it is still one number, and a USD figure and a differently-
  priced currency's figure summed into it is just as mixed. Same gate now applies there.

- The zero-prompt-total gate in InferenceParser.accountant asked whenever
  pctx.ReportedOps() was non-empty, reasoning that the pass before any data arrives
  has no ops either. That was wrong: a structural op (tool-prune's removal, say)
  reports during OnRequest, before the response exists, so that pass's ops list is
  not empty either — and asking there calls Host.Compute with an inference extension
  that is still all zeros, which Compute latches forever, so the real counts that
  arrive on a later pass are never priced at all. Reproduced by clawgenti; fixed by
  gating on pctx.StatusCode (set once, when the response is read) instead of on
  ReportedOps. Added a regression test pinning the exact two-pass sequence.

Also dismissed the same 2 alerts' re-raised instances (rossoctl#365, rossoctl#370) after they shifted
line following the rebase onto main — the earlier dismissal (rossoctl#372, rossoctl#373) stopped
applying once that commit was superseded.

Assisted-By: Claude Sonnet 5 <[email protected]>
Signed-off-by: DAVID BOAZ <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants