
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
adk-agui-py-middleware
Advanced tools
Python middleware bridging Google ADK agents with AGUI protocol via Server-Sent Events for real-time agent interactions
A professional Python middleware library that bridges Agent Development Kit (ADK) agents with AGUI (Agent UI) protocol, providing Server-Sent Events (SSE) streaming capabilities for real-time agent interactions.
This middleware facilitates seamless integration between Google's Agent Development Kit and AGUI-compatible frontends, enabling developers to build interactive agent applications with real-time streaming responses. The library handles agent execution, session management, event encoding, and error handling in a production-ready framework.
The middleware follows a modular architecture with clear separation of concerns:
├── base_abc/ # Abstract base classes
├── config/ # Configuration and logging setup
├── data_model/ # Pydantic models and data structures
├── endpoint.py # FastAPI endpoint registration
├── event/ # Event handling and error events
├── handler/ # Request and session handlers
├── loggers/ # Logging infrastructure
├── manager/ # Session and resource management
├── sse_service.py # Core SSE service implementation
└── tools/ # Utility functions and converters
pip install adk-agui-py-middleware
Available on PyPI: https://pypi.org/project/adk-agui-py-middleware/
google-adk>=1.10.0
)ag-ui-protocol>=0.1.8
)pydantic>=2.11.7
)# Using uv (recommended)
uv sync
# Or using pip
pip install -r requirements.txt
from fastapi import FastAPI
from google.adk.agents import BaseAgent
from adk_agui_middleware import register_agui_endpoint, SSEService
from adk_agui_middleware.data_model.context import RunnerConfig, ContextConfig
# Create your FastAPI app
app = FastAPI()
# Initialize your ADK agent
agent = BaseAgent() # Your custom agent implementation
# Configure context extraction
context_config = ContextConfig(
app_name="my-agent-app",
user_id="user-123", # Can be a callable for dynamic extraction
)
# Configure runner services
runner_config = RunnerConfig(
use_in_memory_services=True # Use in-memory services for development
)
# Create SSE service
sse_service = SSEService(
agent=agent,
runner_config=runner_config,
context_config=context_config
)
# Register the AGUI endpoint
register_agui_endpoint(app, sse_service, path="/agui")
For multi-tenant applications, you can extract context dynamically from requests:
from ag_ui.core import RunAgentInput
from fastapi import Request
async def extract_user_id(agui_content: RunAgentInput, request: Request) -> str:
"""Extract user ID from JWT token or headers"""
token = request.headers.get("authorization")
# Your authentication logic here
return decoded_user_id
async def extract_app_name(agui_content: RunAgentInput, request: Request) -> str:
"""Extract app name from subdomain or headers"""
host = request.headers.get("host", "")
return host.split(".")[0] if "." in host else "default"
context_config = ContextConfig(
app_name=extract_app_name,
user_id=extract_user_id,
session_id=lambda content, req: content.thread_id # Use thread ID as session
)
For production deployments, configure external services:
from google.adk.sessions import DatabaseSessionService
from google.adk.memory import RedisMemoryService
runner_config = RunnerConfig(
use_in_memory_services=False,
session_service=DatabaseSessionService(connection_string="..."),
memory_service=RedisMemoryService(redis_url="..."),
# artifact_service and credential_service as needed
)
Extend the base SSE service for custom behavior:
from adk_agui_middleware.base_abc.sse_service import BaseSSEService
class CustomSSEService(BaseSSEService):
async def get_runner(self, agui_content, request):
# Custom runner logic
pass
async def event_generator(self, runner, encoder):
# Custom event generation
async for event in runner():
# Custom event processing
yield encoder.encode(event)
The middleware includes comprehensive error handling with logging:
from adk_agui_middleware.loggers.logger import setup_logging
# Configure logging
setup_logging(level="INFO")
# Error events are automatically generated for:
# - Agent execution errors
# - Encoding failures
# - Tool execution errors
# - Session management issues
Handle tool calls and results seamlessly:
# Tool calls are automatically extracted from AGUI messages
# Tool results are processed and converted to the appropriate format
# No additional configuration required - handled by UserMessageHandler
SSEService
: Main service implementation for handling agent interactionsregister_agui_endpoint()
: Function to register the AGUI endpoint on FastAPIContextConfig
: Configuration for extracting context from requestsRunnerConfig
: Configuration for ADK runner and servicesUserMessageHandler
: Processes user messages and tool resultsSessionParameter
: Session identification parametersBaseEvent
: Base class for agent eventsThe project uses comprehensive linting and formatting:
# Format code
ruff format
# Lint code
ruff check
# Type checking
mypy src/
# Run tests (configure based on your test setup)
pytest
# With coverage
pytest --cov=adk_agui_middleware
Configure the middleware using environment variables or configuration files:
# Logging level
LOG_LEVEL=INFO
# Service configurations
USE_IN_MEMORY_SERVICES=true
SESSION_SERVICE_URL=redis://localhost:6379
from adk_agui_middleware.config.log import setup_logging
# Configure logging
setup_logging(
level="DEBUG",
format="json", # or "text"
output="file" # or "console"
)
This project is inspired by and builds upon the foundational work of @contextablemark and their AG-UI implementation. We extend our gratitude for their innovative approach to agent-UI integration, which provided essential architectural insights and design patterns that shaped this middleware development.
This project is licensed under the terms specified in the LICENSE file.
For issues and questions:
FAQs
Python middleware bridging Google ADK agents with AGUI protocol via Server-Sent Events for real-time agent interactions
We found that adk-agui-py-middleware demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.