vLLM über den Agenten starten und stoppen

- Agent verwaltet die in seiner Konfiguration festgelegten vLLM-Instanzen:
  Start in eigener Prozessgruppe, Bereitschaft über /health, Stoppen der
  ganzen Gruppe, Absturzerkennung mit Log-Auszug, Stoppen aller beim Beenden
- Proxy bindet vLLM unter /vllm an, leitet nach dem Feld model an die
  Instanz weiter und erfährt die Instanzen vom Agenten
- Scheduler reserviert beim Verdrängen den Platz für das anfragende Modell,
  damit keine andere wartende Anfrage ihn belegt (kein Hin- und Herladen)
- tools/fake_vllm.py zum Testen ohne GPU, agent.example.toml

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Stephan RehfeldandClaude Opus 5.5 committed 2026-11-20 11:37:24 +01:00
1 parent c5d618ed09
commit 566405d12f
13 files changed
+1053 -199

No files matched your search

+46 -9
View File
@@ -57,7 +57,7 @@ pub fn openai_error(status: StatusCode, message: &str) -> Response {
pub fn engine_error(engine: Engine, status: StatusCode, message: &str) -> Response {
match engine {
Engine::Ollama => error_response(status, message),
Engine::LlamaCpp => openai_error(status, message),
Engine::LlamaCpp | Engine::Vllm => openai_error(status, message),
}
}
@@ -94,8 +94,35 @@ async fn status(State(st): State<AppState>) -> Json<Value> {
Json(st.sched.snapshot())
}
async fn vllm() -> Response {
openai_error(StatusCode::NOT_IMPLEMENTED, "vLLM ist noch nicht angebunden")
async fn vllm(
State(st): State<AppState>,
Extension(KeyId(key_id)): Extension<KeyId>,
method: Method,
uri: Uri,
headers: HeaderMap,
body: Bytes,
) -> Response {
let path = uri.path().strip_prefix("/vllm").unwrap_or("/").to_string();
// Entwickler- und Verwaltungsendpunkte von vLLM
if matches!(
path.as_str(),
"/sleep" | "/wake_up" | "/is_sleeping" | "/reset_prefix_cache" | "/reset_mm_cache"
| "/start_profile" | "/stop_profile" | "/collective_rpc" | "/scale_elastic_ep"
| "/update_weights" | "/load_lora_adapter" | "/unload_lora_adapter"
) {
return openai_error(StatusCode::FORBIDDEN, "vLLM-Instanzen verwaltet der Proxy");
}
if method == Method::GET && matches!(path.as_str(), "/models" | "/v1/models") {
// Gestoppte Instanzen können nicht antworten; die Liste kommt deshalb vom Proxy.
let data: Vec<Value> = st
.sched
.catalog_models(Engine::Vllm)
.into_iter()
.map(|id| json!({ "id": id, "object": "model", "owned_by": "vllm" }))
.collect();
return Json(json!({ "object": "list", "data": data })).into_response();
}
handle(st, Some(key_id), Engine::Vllm, path, uri.query(), method, headers, body).await
}
async fn ollama(
@@ -182,7 +209,7 @@ async fn merged_list(st: &AppState, engine: Engine, path: &str, field: &str) ->
}
fn is_openai_path(engine: Engine, path: &str) -> bool {
path.starts_with("/v1/") || (engine == Engine::LlamaCpp && !path.starts_with("/api/"))
path.starts_with("/v1/") || (engine != Engine::Ollama && !path.starts_with("/api/"))
}
#[allow(clippy::too_many_arguments)]
@@ -203,14 +230,14 @@ async fn handle(
.and_then(Value::as_str)
.map(str::to_string);
let mut node = None;
let mut target = None;
let mut guard = None;
if let Some(model) = &model {
let key = match st.sched.locate(engine, model).await {
Ok(key) => key,
Err(e) => return engine_error(engine, StatusCode::NOT_FOUND, &e.to_string()),
};
node = Some(key.node);
target = st.sched.model_url(&key);
// /api/show liest nur Metadaten und braucht kein geladenes Modell.
if !(engine == Engine::Ollama && path == "/api/show") {
match st.sched.acquire(key).await {
@@ -249,8 +276,18 @@ async fn handle(
}
}
let node = node.or_else(|| st.sched.nodes_with(engine).first().copied());
let Some(base) = node.and_then(|n| st.sched.engine_url(n, engine)) else {
// Ohne Modell geht die Anfrage an den ersten Rechner. vLLM hat keine gemeinsame Adresse.
if target.is_none() && engine == Engine::Vllm {
if path == "/health" {
return StatusCode::OK.into_response();
}
return openai_error(StatusCode::BAD_REQUEST, "das Feld model fehlt");
}
let target = target.or_else(|| {
let node = st.sched.nodes_with(engine).first().copied()?;
st.sched.engine_url(node, engine).map(str::to_string)
});
let Some(base) = target else {
return engine_error(engine, StatusCode::NOT_FOUND, "Engine nicht konfiguriert");
};
let url = match query {
@@ -268,5 +305,5 @@ async fn handle(
// Unauthentifizierte Statusabfragen ("/", /api/version) werden nicht verbucht.
let db = st.db.clone();
let record = key_id.is_some();
forward(&st.http, db, Forward { method, url, headers, body, usage, guard, record }).await
forward(&st.http, db, Forward { method, url, headers, body, usage, guard, engine, record }).await
}