|
20 | 20 | import logging
|
21 | 21 | import os
|
22 | 22 | from pathlib import Path
|
| 23 | +import shutil |
23 | 24 | import time
|
24 | 25 | import traceback
|
25 | 26 | import typing
|
|
32 | 33 | from fastapi import FastAPI
|
33 | 34 | from fastapi import HTTPException
|
34 | 35 | from fastapi import Query
|
| 36 | +from fastapi import UploadFile |
35 | 37 | from fastapi.middleware.cors import CORSMiddleware
|
36 | 38 | from fastapi.responses import RedirectResponse
|
37 | 39 | from fastapi.responses import StreamingResponse
|
|
51 | 53 | from typing_extensions import override
|
52 | 54 | from watchdog.events import FileSystemEventHandler
|
53 | 55 | from watchdog.observers import Observer
|
54 |
| -import yaml |
55 | 56 |
|
56 | 57 | from ..agents import RunConfig
|
57 | 58 | from ..agents.live_request_queue import LiveRequest
|
@@ -212,14 +213,6 @@ class GetEventGraphResult(common.BaseModel):
|
212 | 213 | dot_src: str
|
213 | 214 |
|
214 | 215 |
|
215 |
| -class AgentBuildRequest(common.BaseModel): |
216 |
| - agent_name: str |
217 |
| - agent_type: str |
218 |
| - model: str |
219 |
| - description: str |
220 |
| - instruction: str |
221 |
| - |
222 |
| - |
223 | 216 | def get_fast_api_app(
|
224 | 217 | *,
|
225 | 218 | agents_dir: str,
|
@@ -820,26 +813,30 @@ async def delete_artifact(
|
820 | 813 |
|
821 | 814 | @working_in_progress("builder_save is not ready for use.")
|
822 | 815 | @app.post("/builder/save", response_model_exclude_none=True)
|
823 |
| - async def builder_build(req: AgentBuildRequest): |
| 816 | + async def builder_build(files: list[UploadFile]) -> bool: |
824 | 817 | base_path = Path.cwd() / agents_dir
|
825 |
| - agent = { |
826 |
| - "agent_class": req.agent_type, |
827 |
| - "name": req.agent_name, |
828 |
| - "model": req.model, |
829 |
| - "description": req.description, |
830 |
| - "instruction": f"""{req.instruction}""", |
831 |
| - } |
832 |
| - try: |
833 |
| - agent_dir = os.path.join(base_path, req.agent_name) |
834 |
| - os.makedirs(agent_dir, exist_ok=True) |
835 |
| - file_path = os.path.join(agent_dir, "root_agent.yaml") |
836 |
| - with open(file_path, "w") as file: |
837 |
| - yaml.dump(agent, file, default_flow_style=False) |
838 |
| - agent_loader.load_agent(agent_name=req.agent_name) |
839 |
| - return True |
840 |
| - except Exception as e: |
841 |
| - logger.exception("Error in builder_build: %s", e) |
842 |
| - return False |
| 818 | + |
| 819 | + for file in files: |
| 820 | + try: |
| 821 | + # File name format: {app_name}/{agent_name}.yaml |
| 822 | + if not file.filename: |
| 823 | + logger.exception("Agent name is missing in the input files") |
| 824 | + return False |
| 825 | + |
| 826 | + agent_name, filename = file.filename.split("/") |
| 827 | + |
| 828 | + agent_dir = os.path.join(base_path, agent_name) |
| 829 | + os.makedirs(agent_dir, exist_ok=True) |
| 830 | + file_path = os.path.join(agent_dir, filename) |
| 831 | + |
| 832 | + with open(file_path, "w") as buffer: |
| 833 | + shutil.copyfileobj(file.file, buffer) |
| 834 | + |
| 835 | + except Exception as e: |
| 836 | + logger.exception("Error in builder_build: %s", e) |
| 837 | + return False |
| 838 | + |
| 839 | + return True |
843 | 840 |
|
844 | 841 | @app.post("/run", response_model_exclude_none=True)
|
845 | 842 | async def agent_run(req: AgentRunRequest) -> list[Event]:
|
|
0 commit comments