Victor Dibia fe96f7de24
Add Session Saving to AGS (#4369)
* fix import issue related to agentchat update #4245

* update uv lock file

* fix db auto_upgrade logic issue.

* im prove msg rendering issue

* Support termination condition combination. Closes #4325

* fix db instantiation bug

* update yarn.lock, closes #4260 #4262

* remove deps for now with vulnerabilities found by dependabot #4262

* update db tests

* add ability to load sessions from db ..

* format updates, add format checks to ags

* format check fixes

* linting and ruff check fixes

* make tests for ags non-parrallel to avoid db race conditions.

* format updates

* fix concurrency issue

* minor ui tweaks, move run start to websocket

* lint fixes

* update uv.lock

* Update python/packages/autogen-studio/autogenstudio/datamodel/types.py

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>

* Update python/packages/autogen-studio/autogenstudio/teammanager.py

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>

* reuse user proxy from agentchat

* ui tweaks

---------

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
Co-authored-by: Hussein Mozannar <hmozannar@microsoft.com>
2024-11-26 15:39:36 -08:00

66 lines
2.0 KiB
Python

# /api/runs routes
from typing import Dict
from uuid import UUID
from fastapi import APIRouter, Body, Depends, HTTPException
from pydantic import BaseModel
from ...datamodel import Message, MessageConfig, Run, RunStatus, Session, Team
from ..deps import get_db, get_team_manager, get_websocket_manager
router = APIRouter()
class CreateRunRequest(BaseModel):
session_id: int
user_id: str
@router.post("/")
async def create_run(
request: CreateRunRequest,
db=Depends(get_db),
) -> Dict:
"""Create a new run with initial state"""
session_response = db.get(
Session, filters={"id": request.session_id, "user_id": request.user_id}, return_json=False
)
if not session_response.status or not session_response.data:
raise HTTPException(status_code=404, detail="Session not found")
try:
# Create run with default state
run = db.upsert(
Run(
session_id=request.session_id,
status=RunStatus.CREATED,
task=None, # Will be set when run starts
team_result=None,
),
return_json=False,
)
return {"status": run.status, "data": {"run_id": str(run.data.id)}}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e)) from e
# We might want to add these endpoints:
@router.get("/{run_id}")
async def get_run(run_id: UUID, db=Depends(get_db)) -> Dict:
"""Get run details including task and result"""
run = db.get(Run, filters={"id": run_id}, return_json=False)
if not run.status or not run.data:
raise HTTPException(status_code=404, detail="Run not found")
return {"status": True, "data": run.data[0]}
@router.get("/{run_id}/messages")
async def get_run_messages(run_id: UUID, db=Depends(get_db)) -> Dict:
"""Get all messages for a run"""
messages = db.get(Message, filters={"run_id": run_id}, order="created_at asc", return_json=False)
return {"status": True, "data": messages.data}