Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 175 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/agentic-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ agentic-core = { path = "../agentic-core" }
axum = "0.8"
clap = { version = "4", features = ["derive", "env"] }
http = "1"
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
tower-http = { version = "0.6", features = ["cors"] }
Expand Down
6 changes: 4 additions & 2 deletions crates/agentic-server/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use agentic_core::proxy::ProxyState;
use axum::Router;
use axum::routing::post;
use axum::routing::{get, post};

use crate::handler::proxy_responses;
use crate::handler::{health, proxy_responses, ready};

pub fn build_router(state: ProxyState) -> Router {
Router::new()
.route("/health", get(health))
.route("/ready", get(ready))
.route("/v1/responses", post(proxy_responses))
.with_state(state)
}
43 changes: 42 additions & 1 deletion crates/agentic-server/src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
use agentic_core::proxy::{ProxyBody, ProxyRequest, ProxyResponse, ProxyState, error_response};
use axum::body::Body;
use axum::extract::State;
use axum::response::Response;
use axum::response::{IntoResponse, Response};
use http::StatusCode;
use tracing::warn;

const MAX_BODY_SIZE: usize = 10 * 1024 * 1024;

pub async fn health() -> impl IntoResponse {
StatusCode::OK
}

pub async fn ready(State(state): State<ProxyState>) -> impl IntoResponse {
let base = state.config.llm_api_base.trim_end_matches('/');
let url = format!("{base}/health");

let mut headers = reqwest::header::HeaderMap::new();
if let Some(key) = state.config.openai_api_key.as_deref() {
let trimmed = key.trim();
if !trimmed.is_empty() {
if let Ok(v) = reqwest::header::HeaderValue::from_str(&format!("Bearer {trimmed}")) {
headers.insert(reqwest::header::AUTHORIZATION, v);
}
}
}

let client = reqwest::Client::builder()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this reqwest is missing authorization headers. in readiness.rs we do insert the headers.

can you fix this asymmetry?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — fixed in 70c3849. The readiness probe now injects the Bearer token from OPENAI_API_KEY the same way readiness.rs does at startup.

.timeout(std::time::Duration::from_secs(2))
.default_headers(headers)
.build();

let Ok(client) = client else {
return StatusCode::SERVICE_UNAVAILABLE;
};

match client.get(&url).send().await {
Ok(resp) if resp.status().is_success() => StatusCode::OK,
Ok(resp) => {
warn!("LLM backend not ready: status {}", resp.status());
StatusCode::SERVICE_UNAVAILABLE
}
Err(e) => {
warn!("LLM backend unreachable: {e}");
StatusCode::SERVICE_UNAVAILABLE
}
}
}

fn convert_response(resp: ProxyResponse) -> Response {
let mut builder = Response::builder().status(resp.status);
for (name, value) in &resp.headers {
Expand Down
Loading