Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
9 changes: 4 additions & 5 deletions src/infrastructure/deepagent/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,13 @@ async def stream(self, thread_id: str, message: str) -> AsyncIterator[str]:
config = self._build_config(thread_id)
logger.info("[thread=%s] Streaming agent response", thread_id)
try:
async for event in self._graph.astream(
async for chunk, _metadata in self._graph.astream(
{"messages": [{"role": "human", "content": message}]},
config=config,
stream_mode="messages-tuple",
stream_mode="messages",
):
msg_type, msg = event
if msg_type == "ai" and hasattr(msg, "content") and msg.content:
yield msg.content
if hasattr(chunk, "content") and chunk.content and chunk.type == "AIMessageChunk":
yield chunk.content
except Exception as e:
logger.exception("[thread=%s] Streaming error", thread_id)
raise AgentError(f"Streaming error: {e}") from e
Expand Down
9 changes: 9 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path

from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse

from src.application.routes.agents import router as agents_router
Expand Down Expand Up @@ -95,6 +96,14 @@ async def lifespan(_app: FastAPI):
lifespan=lifespan,
)

app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:8030"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

app.include_router(health_router)
app.include_router(threads_router)
app.include_router(chat_router)
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_runner_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ async def test_stream_with_tracing_injects_callbacks(self, mock_tracing_provider
async def mock_astream(*_args, **_kwargs):
mock_msg = MagicMock()
mock_msg.content = "chunk"
yield ("ai", mock_msg)
mock_msg.type = "AIMessageChunk"
yield (mock_msg, {"langgraph_node": "agent"})

mock_graph.astream = mock_astream

Expand Down
Loading