|
12 | 12 | from langgraph.graph.graph import CompiledGraph |
13 | 13 | from langchain_core.runnables.config import RunnableConfig |
14 | 14 | from datadog import initialize, statsd |
15 | | -import aioboto3 |
16 | 15 | import aiohttp |
17 | 16 |
|
18 | 17 | from onchain.pools.protocol import ProtocolRegistry |
|
51 | 50 | from server.activity_tracker import ActivityTracker |
52 | 51 | from server.utils import extract_patterns, convert_to_agent_msg |
53 | 52 | from server.dynamodb_helpers import DatabaseManager |
| 53 | +from agent.integrations.sentient.sentient_agent import BitQuantSentientAgent |
| 54 | + |
54 | 55 | from . import service |
55 | 56 | from .auth import FirebaseIDTokenData, get_current_user |
56 | 57 |
|
@@ -366,6 +367,65 @@ async def get_activity_stats( |
366 | 367 | logging.error(f"Error getting activity stats: {e}") |
367 | 368 | raise HTTPException(status_code=500, detail="Internal server error") |
368 | 369 |
|
| 370 | + @app.post("/api/sentient/assist") |
| 371 | + async def sentient_assist( |
| 372 | + request: Request, |
| 373 | + user: FirebaseIDTokenData = Depends(get_current_user), |
| 374 | + ): |
| 375 | + """ |
| 376 | + Proxy endpoint for Sentient Agent. Accepts JSON with 'session' and 'query', |
| 377 | + calls BitQuantSentientAgent.assist, and returns the output blocks as JSON. |
| 378 | + """ |
| 379 | + try: |
| 380 | + data = await request.json() |
| 381 | + session_dict = data.get("session") |
| 382 | + query_dict = data.get("query") |
| 383 | + |
| 384 | + class SentientAssistSession: |
| 385 | + def __init__(self, processor_id, activity_id, request_id, interactions): |
| 386 | + self.processor_id = processor_id |
| 387 | + self.activity_id = activity_id |
| 388 | + self.request_id = request_id |
| 389 | + self.interactions = interactions or [] |
| 390 | + |
| 391 | + def get_interactions(self): |
| 392 | + return self.interactions |
| 393 | + |
| 394 | + class SentientAssistQuery: |
| 395 | + def __init__(self, id, prompt): |
| 396 | + self.id = id |
| 397 | + self.prompt = prompt |
| 398 | + |
| 399 | + session = SentientAssistSession( |
| 400 | + processor_id=session_dict.get("processor_id"), |
| 401 | + activity_id=session_dict.get("activity_id"), |
| 402 | + request_id=session_dict.get("request_id"), |
| 403 | + interactions=session_dict.get("interactions", []), |
| 404 | + ) |
| 405 | + query = SentientAssistQuery( |
| 406 | + id=query_dict.get("id"), |
| 407 | + prompt=query_dict.get("prompt"), |
| 408 | + ) |
| 409 | + |
| 410 | + class SentientFlaskResponseHandler: |
| 411 | + def __init__(self): |
| 412 | + self.blocks = [] |
| 413 | + |
| 414 | + async def emit_text_block(self, label, text): |
| 415 | + self.blocks.append({"label": label, "text": text}) |
| 416 | + |
| 417 | + async def complete(self): |
| 418 | + pass |
| 419 | + |
| 420 | + agent = BitQuantSentientAgent() |
| 421 | + handler = SentientFlaskResponseHandler() |
| 422 | + |
| 423 | + await agent.assist(session, query, handler) |
| 424 | + return JSONResponse(content={"blocks": handler.blocks}) |
| 425 | + except Exception as e: |
| 426 | + logging.exception("Error in sentient_assist endpoint") |
| 427 | + return JSONResponse(status_code=500, content={"error": str(e)}) |
| 428 | + |
369 | 429 | return app |
370 | 430 |
|
371 | 431 |
|
|
0 commit comments