Remove deep ask from ag-ui server

This commit is contained in:
Yiorgis Gozadinos 2025-12-17 10:10:03 +02:00
parent 45de9bf0d5
commit 921893cff5
No known key found for this signature in database
2 changed files with 18 additions and 78 deletions

View file

@ -119,7 +119,7 @@ URLs are also supported - the content is fetched and converted to markdown.
## AG-UI Server ## AG-UI Server
The AG-UI server provides HTTP streaming of both research and deep ask graph execution using Server-Sent Events (SSE). The AG-UI server provides HTTP streaming of research graph execution using Server-Sent Events (SSE).
### Starting the AG-UI Server ### Starting the AG-UI Server
@ -131,7 +131,6 @@ This starts an HTTP server (default: http://0.0.0.0:8000) that exposes:
- `GET /health` - Health check endpoint - `GET /health` - Health check endpoint
- `POST /v1/research/stream` - Research graph streaming endpoint - `POST /v1/research/stream` - Research graph streaming endpoint
- `POST /v1/deep-ask/stream` - Deep ask graph streaming endpoint
### Configuration ### Configuration
@ -154,9 +153,9 @@ agui:
- **cors_methods**: Allowed HTTP methods (default: `["GET", "POST", "OPTIONS"]`) - **cors_methods**: Allowed HTTP methods (default: `["GET", "POST", "OPTIONS"]`)
- **cors_headers**: Allowed headers (default: `["*"]`) - **cors_headers**: Allowed headers (default: `["*"]`)
### Using the Streaming Endpoints ### Using the Streaming Endpoint
Both endpoints accept POST requests with the same AG-UI RunAgentInput format and stream AG-UI events. The endpoint accepts POST requests with AG-UI RunAgentInput format and streams AG-UI events.
**Request format:** **Request format:**
```json ```json
@ -171,7 +170,7 @@ Both endpoints accept POST requests with the same AG-UI RunAgentInput format and
} }
``` ```
**Research endpoint example:** **Example:**
```bash ```bash
curl -X POST http://localhost:8000/v1/research/stream \ curl -X POST http://localhost:8000/v1/research/stream \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
@ -183,24 +182,12 @@ curl -X POST http://localhost:8000/v1/research/stream \
--no-buffer --no-buffer
``` ```
**Deep ask endpoint example:**
```bash
curl -X POST http://localhost:8000/v1/deep-ask/stream \
-H "Content-Type: application/json" \
-d '{
"state": {
"question": "How does haiku.rag handle document chunking?",
"use_citations": true
}
}' \
--no-buffer
```
The `--no-buffer` flag ensures curl displays events as they arrive instead of buffering them. The `--no-buffer` flag ensures curl displays events as they arrive instead of buffering them.
**Note:** The `state` object can include: **Note:** The `state` object can include:
- `question`: The question to answer (required) - `question`: The question to answer (required)
- `use_citations`: Enable citations in deep ask responses (optional, deep ask only) - `max_iterations`: Maximum research iterations (optional, defaults to config)
- `confidence_threshold`: Confidence threshold for early termination (optional, defaults to config)
**Response:** Server-Sent Events stream with AG-UI protocol events: **Response:** Server-Sent Events stream with AG-UI protocol events:
- `RUN_STARTED` - Graph execution started - `RUN_STARTED` - Graph execution started

View file

@ -154,14 +154,14 @@ def format_sse_event(event: AGUIEvent) -> str:
def create_agui_server( # pragma: no cover def create_agui_server( # pragma: no cover
config: "AppConfig", db_path: Path | None = None config: "AppConfig", db_path: Path | None = None
) -> Starlette: ) -> Starlette:
"""Create AG-UI server with both research and deep ask endpoints. """Create AG-UI server with research endpoint.
Args: Args:
config: Application config with research and qa settings config: Application config with research settings
db_path: Optional database path override db_path: Optional database path override
Returns: Returns:
Starlette app with research and deep ask endpoints Starlette app with research endpoint
""" """
from haiku.rag.client import HaikuRAG from haiku.rag.client import HaikuRAG
from haiku.rag.graph.research.dependencies import ResearchContext from haiku.rag.graph.research.dependencies import ResearchContext
@ -189,7 +189,14 @@ def create_agui_server( # pragma: no cover
if messages: if messages:
question = messages[0].get("content", "") question = messages[0].get("content", "")
context = ResearchContext(original_question=question) context = ResearchContext(original_question=question)
return ResearchState.from_config(context=context, config=config) max_iterations = input_state.get("max_iterations")
confidence_threshold = input_state.get("confidence_threshold")
return ResearchState.from_config(
context=context,
config=config,
max_iterations=max_iterations,
confidence_threshold=confidence_threshold,
)
def research_deps_factory(input_config: dict[str, Any]) -> ResearchDeps: def research_deps_factory(input_config: dict[str, Any]) -> ResearchDeps:
effective_db_path = ( effective_db_path = (
@ -199,33 +206,7 @@ def create_agui_server( # pragma: no cover
) )
return ResearchDeps(client=get_client(effective_db_path)) return ResearchDeps(client=get_client(effective_db_path))
# Deep ask graph factories (uses research graph with quick settings) # Create event stream function
def deep_ask_graph_factory() -> Graph:
return build_research_graph(config)
def deep_ask_state_factory(input_state: dict[str, Any]) -> ResearchState:
question = input_state.get("question", "")
if not question:
messages = input_state.get("messages", [])
if messages:
question = messages[0].get("content", "")
context = ResearchContext(original_question=question)
return ResearchState.from_config(
context=context,
config=config,
max_iterations=2,
confidence_threshold=0.0,
)
def deep_ask_deps_factory(input_config: dict[str, Any]) -> ResearchDeps:
effective_db_path = (
db_path
or input_config.get("db_path")
or config.storage.data_dir / "haiku.rag.lancedb"
)
return ResearchDeps(client=get_client(effective_db_path))
# Create event stream functions for each graph type
async def research_event_stream( async def research_event_stream(
input_data: RunAgentInput, input_data: RunAgentInput,
) -> AsyncIterator[str]: ) -> AsyncIterator[str]:
@ -238,18 +219,6 @@ def create_agui_server( # pragma: no cover
event_data = format_sse_event(event) event_data = format_sse_event(event)
yield event_data yield event_data
async def deep_ask_event_stream(
input_data: RunAgentInput,
) -> AsyncIterator[str]:
"""Generate SSE event stream from deep ask graph execution."""
graph = deep_ask_graph_factory()
initial_state = deep_ask_state_factory(input_data.state)
deps = deep_ask_deps_factory(input_data.config)
async for event in stream_graph(graph, initial_state, deps):
event_data = format_sse_event(event)
yield event_data
# Endpoint handlers # Endpoint handlers
async def stream_research(request: Request) -> StreamingResponse: async def stream_research(request: Request) -> StreamingResponse:
"""Research graph streaming endpoint.""" """Research graph streaming endpoint."""
@ -266,21 +235,6 @@ def create_agui_server( # pragma: no cover
}, },
) )
async def stream_deep_ask(request: Request) -> StreamingResponse:
"""Deep ask graph streaming endpoint."""
body = await request.json()
input_data = RunAgentInput(**body)
return StreamingResponse(
deep_ask_event_stream(input_data),
media_type="text/event-stream",
headers={
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"X-Accel-Buffering": "no",
},
)
async def health_check(_: Request) -> JSONResponse: async def health_check(_: Request) -> JSONResponse:
"""Health check endpoint.""" """Health check endpoint."""
return JSONResponse({"status": "healthy"}) return JSONResponse({"status": "healthy"})
@ -288,7 +242,6 @@ def create_agui_server( # pragma: no cover
# Define routes # Define routes
routes = [ routes = [
Route("/v1/research/stream", stream_research, methods=["POST"]), Route("/v1/research/stream", stream_research, methods=["POST"]),
Route("/v1/deep-ask/stream", stream_deep_ask, methods=["POST"]),
Route("/health", health_check, methods=["GET"]), Route("/health", health_check, methods=["GET"]),
] ]