fix: connect 10 unconnected backend modules to real code paths (context_builder→agent_runner, agent_permissions→agent_runner, agent_tools→agent_runner, data_policy→agent_runner, oversight→agent_runner+migration 0128, transparency→agent_runner, agent_stream→agent_routes SSE endpoint, agent_memory AI-module deleted, decision_guard→engine, require_approval→agent_runner), 11 integration tests passing
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
This commit is contained in:
@@ -601,3 +601,55 @@ async def send_agent_message_endpoint(
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
# ─── Punkt 7: SSE Streaming Endpoint (agent_stream.py) ─────────────────────
|
||||
|
||||
|
||||
@router.post("/{id}/stream")
|
||||
async def stream_agent_run(
|
||||
id: str,
|
||||
body: AgentMessageRequest,
|
||||
current_user: dict[str, Any] = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Stream an agent run via Server-Sent Events (SSE).
|
||||
|
||||
Uses ``app.ai.agent_stream.stream_react_loop`` to emit step events
|
||||
in real-time as the agent processes.
|
||||
"""
|
||||
from fastapi.responses import StreamingResponse
|
||||
from app.ai.agent_stream import stream_react_loop
|
||||
from app.plugins.builtins.ai_assistant.contracts import get_tool_registry
|
||||
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
user_id = uuid.UUID(current_user["user_id"])
|
||||
try:
|
||||
aid = uuid.UUID(id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid agent ID") from None
|
||||
|
||||
agent = await AgentService.get_by_id(db, tenant_id, aid)
|
||||
if agent is None:
|
||||
raise HTTPException(status_code=404, detail="Agent not found")
|
||||
if not agent.is_active:
|
||||
raise HTTPException(status_code=400, detail="Agent is not active")
|
||||
|
||||
registry = get_tool_registry()
|
||||
tool_ids: list[str] = list(agent.tool_ids or [])
|
||||
tools = registry.get_by_names(tool_ids) if tool_ids else []
|
||||
tool_schemas = [t.to_openai_schema() for t in tools] if tools else []
|
||||
|
||||
return StreamingResponse(
|
||||
stream_react_loop(
|
||||
agent_definition=agent,
|
||||
user_message=body.message,
|
||||
tools=tool_schemas,
|
||||
tool_registry=registry,
|
||||
db=db,
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
agent_run_id=aid,
|
||||
),
|
||||
media_type="text/event-stream",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user