mirror of
https://github.com/microsoft/autogen.git
synced 2025-08-03 22:32:20 +00:00

<!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? Fix termination UI in AGS, ensure it can be edited correctly <img width="1269" alt="image" src="https://github.com/user-attachments/assets/eaa7a92f-a1ea-4ab4-a679-2894ac441311" /> <img width="1273" alt="image" src="https://github.com/user-attachments/assets/6db81068-932f-4d4e-9512-279770c02bf2" /> <img width="1270" alt="image" src="https://github.com/user-attachments/assets/5ca9df7d-b968-46c9-9d62-becd78809273" /> <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5872 ## Checks - [ ] I've included any doc changes needed for <https://microsoft.github.io/autogen/>. See <https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to build and test documentation locally. - [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [ ] I've made sure all auto checks have passed.
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
# /api/runs routes
|
|
from typing import Dict
|
|
|
|
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,
|
|
user_id=request.user_id,
|
|
task={}, # Will be set when run starts
|
|
team_result={},
|
|
),
|
|
return_json=False,
|
|
)
|
|
return {"status": run.status, "data": {"run_id": 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: int, 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: int, 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}
|