-
Notifications
You must be signed in to change notification settings - Fork 11
feat: migrate to Praxis filter-based proxy architecture #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| admin: | ||
| address: "127.0.0.1:9901" | ||
|
|
||
| listeners: | ||
| - name: agentic-api | ||
| address: "0.0.0.0:9000" | ||
| filter_chains: [agentic] | ||
|
|
||
| filter_chains: | ||
| - name: agentic | ||
| filters: | ||
| - filter: state_hydration | ||
| store_base_url: "http://localhost:8080" | ||
| - filter: agentic_loop | ||
| max_iterations: 10 | ||
| - filter: tool_dispatch | ||
| - filter: responses_proxy | ||
| vllm_base_url: "http://localhost:8000" | ||
|
|
||
| clusters: | ||
| - name: vllm | ||
| endpoints: ["127.0.0.1:8000"] | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Architecture | ||
|
|
||
| ## Overview | ||
|
|
||
| The vLLM Agentic API is a Rust-based gateway built on [Praxis](https://github.com/praxis-proxy/praxis), a composable filter-based proxy framework. Each gateway concern is an independent Praxis filter, composed into a pipeline via YAML configuration. | ||
|
|
||
| ```mermaid | ||
| graph TD | ||
| Client -->|POST /v1/responses| Gateway[Agentic API Gateway] | ||
| Gateway --> SH[state_hydration filter] | ||
| SH --> AL[agentic_loop filter] | ||
| AL --> TD[tool_dispatch filter] | ||
| TD --> RP[responses_proxy filter] | ||
| RP -->|native proxy| vLLM[vLLM Core] | ||
| SH -.->|hydrate state| Store[State Store] | ||
| TD -.->|execute tools| Tools[MCP / Tool Runtimes] | ||
| AL -.->|loop on tool calls| AL | ||
| ``` | ||
|
|
||
| **Stateless path:** Requests without `previous_response_id` flow straight through to vLLM Core. | ||
|
|
||
| **Stateful path:** The `state_hydration` filter loads conversation history, the request goes to vLLM, and if tool calls are detected, the `agentic_loop` and `tool_dispatch` filters handle execution and re-inference. | ||
|
|
||
| ## Filter Pipeline | ||
|
|
||
| The gateway is a pipeline of [Praxis filters](https://github.com/praxis-proxy/praxis/blob/main/docs/filters.md) — each filter implements the `HttpFilter` trait with hooks for request and response processing. | ||
|
|
||
| | Filter | Phase | Role | | ||
| |--------|-------|------| | ||
| | `state_hydration` | Request | Inspects `previous_response_id` and hydrates conversation history from the state store | | ||
| | `agentic_loop` | Response | Detects `function_call` output items in model responses and re-enters the inference loop | | ||
| | `tool_dispatch` | Response | Executes tool calls (MCP servers, code interpreter, file search) | | ||
| | `responses_proxy` | Request | Sets the upstream to vLLM's `/v1/responses` endpoint and injects auth credentials | | ||
|
|
||
| Filters are configured and ordered in `config/agentic-api.yaml`: | ||
|
|
||
| ```yaml | ||
| filter_chains: | ||
| - name: agentic | ||
| filters: | ||
| - filter: state_hydration | ||
| store_base_url: "http://localhost:8080" | ||
| - filter: agentic_loop | ||
| max_iterations: 10 | ||
| - filter: tool_dispatch | ||
| - filter: responses_proxy | ||
| vllm_base_url: "http://localhost:8000" | ||
| ``` | ||
|
|
||
| Adding, removing, or reordering filters requires no code changes — just edit the YAML. | ||
|
|
||
| ## Why Praxis | ||
|
|
||
| - **Composable** — Each filter is self-contained with no knowledge of other filters in the pipeline | ||
| - **YAML-configured** — The pipeline can be reconfigured without code changes | ||
| - **Native streaming** — Praxis/Pingora handles SSE streaming natively, delivering tokens to clients in real time | ||
| - **Hot reload** — Filter pipelines can be reloaded from YAML without restarting the server | ||
| - **AI-optimized** — Built-in body inspection (`StreamBuffer` mode), model-to-header routing, and MCP classification | ||
|
|
||
| ## Key Components | ||
|
|
||
| ### vLLM Core (Stateless Inference) | ||
|
|
||
| The upstream vLLM server implements a stateless version of the Responses API. It handles tokenization, chat templates, and inference. The gateway never duplicates this logic. | ||
|
|
||
| ### State Store | ||
|
|
||
| Provides stateful building blocks: file storage, vector stores, search, and conversation history. The `state_hydration` filter calls into the store to load conversation context before inference. | ||
|
|
||
| ### Tool Runtimes | ||
|
|
||
| Tool calls detected in model output are dispatched by the `tool_dispatch` filter. Supported runtime types include MCP servers, code interpreter, file search, and web search. | ||
|
|
||
| ## Streaming | ||
|
|
||
| SSE streaming is handled natively by Praxis's underlying [Pingora](https://github.com/cloudflare/pingora) proxy engine. The `responses_proxy` filter sets the upstream target and returns `FilterAction::Continue`, letting Pingora forward the response stream directly to the client — no buffering, no reqwest intermediary. |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from openai import OpenAI | ||
|
|
||
| client = OpenAI() | ||
|
|
||
| # Create a 3-response chain | ||
| resp1 = client.responses.create(model="gpt-4o", input="Remember: the secret word is banana", store=True) | ||
| print(f"resp1: {resp1.id}") | ||
|
|
||
| resp2 = client.responses.create(model="gpt-4o", input="Acknowledge the secret word", previous_response_id=resp1.id, store=True) | ||
| print(f"resp2: {resp2.id}") | ||
|
|
||
| resp3 = client.responses.create(model="gpt-4o", input="Say the secret word again", previous_response_id=resp2.id, store=True) | ||
| print(f"resp3: {resp3.id} → {resp3.output_text}") | ||
|
|
||
| # Delete the middle link | ||
| client.responses.delete(resp2.id) | ||
| print(f"Deleted resp2: {resp2.id}") | ||
|
|
||
| # Try to continue from resp3 — does it still work? | ||
| try: | ||
| resp4 = client.responses.create(model="gpt-4o", input="What was the secret word?", previous_response_id=resp3.id, store=True) | ||
| print(f"resp4: {resp4.id} → {resp4.output_text}") | ||
| print("Chain survived deletion → likely shadow conversation") | ||
| except Exception as e: | ||
| print(f"Chain broke → likely walking the chain: {e}") | ||
|
|
||
| # Also dump resp1 for any hidden fields | ||
| print(f"\nFull resp1 dump keys: {list(resp1.model_dump().keys())}") |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from openai import OpenAI | ||
|
|
||
| client = OpenAI() | ||
|
|
||
| # Test 1: Delete middle link (resp2) | ||
| print("=== Test 1: Delete middle link ===") | ||
| resp1 = client.responses.create(model="gpt-4o", input="Remember: the secret word is banana", store=True) | ||
| print(f"resp1: {resp1.id}") | ||
|
|
||
| resp2 = client.responses.create(model="gpt-4o", input="Acknowledge the secret word", previous_response_id=resp1.id, store=True) | ||
| print(f"resp2: {resp2.id}") | ||
|
|
||
| resp3 = client.responses.create(model="gpt-4o", input="Say the secret word again", previous_response_id=resp2.id, store=True) | ||
| print(f"resp3: {resp3.id} → {resp3.output_text}") | ||
|
|
||
| client.responses.delete(resp2.id) | ||
| print(f"Deleted resp2 (middle link)") | ||
|
|
||
| resp4 = client.responses.create(model="gpt-4o", input="What was the secret word?", previous_response_id=resp3.id, store=True) | ||
| print(f"resp4: {resp4.id} → {resp4.output_text}") | ||
|
|
||
| # Test 2: Delete the source of truth (resp1 — the one with "banana") | ||
| print("\n=== Test 2: Delete source of truth ===") | ||
| r1 = client.responses.create(model="gpt-4o", input="Remember: the secret word is mango", store=True) | ||
| print(f"r1: {r1.id}") | ||
|
|
||
| r2 = client.responses.create(model="gpt-4o", input="Acknowledge the secret word", previous_response_id=r1.id, store=True) | ||
| print(f"r2: {r2.id}") | ||
|
|
||
| r3 = client.responses.create(model="gpt-4o", input="Say the secret word again", previous_response_id=r2.id, store=True) | ||
| print(f"r3: {r3.id} → {r3.output_text}") | ||
|
|
||
| client.responses.delete(r1.id) | ||
| print(f"Deleted r1 (source of 'mango')") | ||
|
|
||
| r4 = client.responses.create(model="gpt-4o", input="What was the secret word?", previous_response_id=r3.id, store=True) | ||
| print(f"r4: {r4.id} → {r4.output_text}") |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| use clap::Args; | ||
|
|
||
| #[derive(Debug, Clone, Args)] | ||
| pub struct RuntimeConfig { | ||
| #[arg(skip)] | ||
| pub llm_api_base: String, | ||
|
|
||
| #[arg(long, env = "OPENAI_API_KEY", hide_env_values = true)] | ||
| pub openai_api_key: Option<String>, | ||
|
|
||
| #[arg(long, default_value = "0.0.0.0")] | ||
| pub gateway_host: String, | ||
|
|
||
| #[arg(long, default_value_t = 9000)] | ||
| pub gateway_port: u16, | ||
|
|
||
| #[arg(long, default_value_t = 600.0)] | ||
| pub vllm_ready_timeout_s: f64, | ||
|
|
||
| #[arg(long, default_value_t = 2.0)] | ||
| pub vllm_ready_interval_s: f64, | ||
| } | ||
|
|
||
| #[must_use] | ||
| pub fn normalize_base_url(url: &str) -> String { | ||
| let mut s = url.trim_end_matches('/').to_owned(); | ||
| if s.ends_with("/v1") { | ||
| s.truncate(s.len() - 3); | ||
| s = s.trim_end_matches('/').to_owned(); | ||
| } | ||
| s | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn strip_trailing_v1() { | ||
| assert_eq!(normalize_base_url("http://host:8000/v1"), "http://host:8000"); | ||
| assert_eq!(normalize_base_url("http://host:8000/v1/"), "http://host:8000"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn no_v1_unchanged() { | ||
| assert_eq!(normalize_base_url("http://host:8000"), "http://host:8000"); | ||
| assert_eq!(normalize_base_url("http://host:8000/"), "http://host:8000"); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| use std::io; | ||
|
|
||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum Error { | ||
| #[error("failed to build HTTP client")] | ||
| HttpClient(#[source] reqwest::Error), | ||
|
|
||
| #[error("vLLM not ready within {timeout_s:.0}s at {url}")] | ||
| VllmTimeout { url: String, timeout_s: f64 }, | ||
|
|
||
| #[error("vLLM subprocess exited before becoming ready: {status}")] | ||
| VllmProcessExited { status: String }, | ||
|
|
||
| #[error(transparent)] | ||
| Io(#[from] io::Error), | ||
|
|
||
| #[error("invalid header value")] | ||
| InvalidHeader(#[from] reqwest::header::InvalidHeaderValue), | ||
|
|
||
| #[error("{0}")] | ||
| Config(String), | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need documentation on what each fields means in this yaml file and what are they used for.
some fields are confusing to guess what it meant to do. like
store_base_urllike related to storage but it's not database url?!Overall the
Praxislibrary is relatively new not sure if it is suitable to rely on it. the maintenance is costly.it is difficult to review this PR and judge as would require the maintainer on
agentic-apto be familiar withPraxis.meanwhile natively writing our own http request gateway would allow us flexibility especially in SSE stream and tool calls.
in terms of testing the
agentic-apirepo functionality as a whole system now it's relying entirely on Praxis is maintained and tested. What If we encounter bugs from Praxis we would need to wait for bug fixes there.I thought based on the last community meeting we would use OGX for CRUD features as it is a well-maintained project?!