[ Web Proxy ]
URL:
Viewing: https://adk.dev/integrations/../../tutorials/../../context/../../agents/models/vllm/ [Back]  [Original]

vLLM - Agent Development Kit (ADK) Agent Development Kit (ADK)
Skip to content
ADK Go 2.0 GA is LIVE with graph workflows and collaborative agents! Get started.
logo [logo]
vLLM
Python [Python] Python TypeScript [TypeScript] JS Go [Go] Go Java [Java] Java Kotlin [Kotlin] Kotlin
[Go]
  1. Home
  2. Build Agents
  3. Models for Agents

vLLM model host for ADK agents

Supported in ADKPython v0.1.0

Tools such as vLLM allow you to host models efficiently and serve them as an OpenAI-compatible API endpoint. You can use vLLM models through the LiteLLM library for Python.

Setup

  1. Deploy Model: Deploy your chosen model using vLLM (or a similar tool). Note the API base URL (e.g., https://your-vllm-endpoint.run.app/v1).
    • Important for ADK Tools: When deploying, ensure the serving tool supports and enables OpenAI-compatible tool/function calling. For vLLM, this might involve flags like --enable-auto-tool-choice and potentially a specific --tool-call-parser, depending on the model. Refer to the vLLM documentation on Tool Use.
  2. Authentication: Determine how your endpoint handles authentication (e.g., API key, bearer token).

Integration Example

The following example shows how to use a vLLM endpoint with ADK agents.

import subprocess
from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm

# --- Example Agent using a Gemma 4 model hosted on a vLLM endpoint ---

# Endpoint URL provided by your vLLM deployment
api_base_url = "https://your-vllm-endpoint.run.app/v1"

# Model name as recognized by *your* vLLM endpoint configuration
model_name_at_endpoint = "hosted_vllm/google/gemma-4-E4B-it" # Example from vllm_test.py

# Authentication (Example: using gcloud identity token for a Cloud Run deployment)
# Adapt this based on your endpoint's security
try:
    gcloud_token = subprocess.check_output(
        ["gcloud", "auth", "print-identity-token", "-q"]
    ).decode().strip()
    auth_headers = {"Authorization": f"Bearer {gcloud_token}"}
except Exception as e:
    print(f"Warning: Could not get gcloud token - {e}. Endpoint might be unsecured or require different auth.")
    auth_headers = None # Or handle error appropriately

agent_vllm = LlmAgent(
    model=LiteLlm(
        model=model_name_at_endpoint,
        api_base=api_base_url,
        # This extra_body values specific to Gemma 4.
        extra_body={
            "chat_template_kwargs": {
                "enable_thinking": True # Enable thinking
            },
            "skip_special_tokens": False # Should be set to False
        },
        # Pass authentication headers if needed
        extra_headers=auth_headers,
        # Alternatively, if endpoint uses an API key:
        # api_key="YOUR_ENDPOINT_API_KEY"
    ),
    name="vllm_agent",
    instruction="You are a helpful assistant running on a self-hosted vLLM endpoint.",
    # ... other agent parameters
)
Back to top

Web Proxy Viewer  |  New URL  |  Original Page