Skip to content

feat: Update builder/save endpoint to accept files as input. Write the agent yaml file to the agent folder #1978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ test = [
"pytest-mock>=3.14.0",
"pytest-xdist>=3.6.1",
"pytest>=8.3.4",
"python-multipart>=0.0.9",
# go/keep-sorted end
]

Expand Down
53 changes: 25 additions & 28 deletions src/google/adk/cli/fast_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import logging
import os
from pathlib import Path
import shutil
import time
import traceback
import typing
Expand All @@ -32,6 +33,7 @@
from fastapi import FastAPI
from fastapi import HTTPException
from fastapi import Query
from fastapi import UploadFile
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse
from fastapi.responses import StreamingResponse
Expand All @@ -51,7 +53,6 @@
from typing_extensions import override
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
import yaml

from ..agents import RunConfig
from ..agents.live_request_queue import LiveRequest
Expand Down Expand Up @@ -212,14 +213,6 @@ class GetEventGraphResult(common.BaseModel):
dot_src: str


class AgentBuildRequest(common.BaseModel):
agent_name: str
agent_type: str
model: str
description: str
instruction: str


def get_fast_api_app(
*,
agents_dir: str,
Expand Down Expand Up @@ -820,26 +813,30 @@ async def delete_artifact(

@working_in_progress("builder_save is not ready for use.")
@app.post("/builder/save", response_model_exclude_none=True)
async def builder_build(req: AgentBuildRequest):
async def builder_build(files: list[UploadFile]) -> bool:
base_path = Path.cwd() / agents_dir
agent = {
"agent_class": req.agent_type,
"name": req.agent_name,
"model": req.model,
"description": req.description,
"instruction": f"""{req.instruction}""",
}
try:
agent_dir = os.path.join(base_path, req.agent_name)
os.makedirs(agent_dir, exist_ok=True)
file_path = os.path.join(agent_dir, "root_agent.yaml")
with open(file_path, "w") as file:
yaml.dump(agent, file, default_flow_style=False)
agent_loader.load_agent(agent_name=req.agent_name)
return True
except Exception as e:
logger.exception("Error in builder_build: %s", e)
return False

for file in files:
try:
# File name format: {app_name}/{agent_name}.yaml
if not file.filename:
logger.exception("Agent name is missing in the input files")
return False

agent_name, filename = file.filename.split("/")

agent_dir = os.path.join(base_path, agent_name)
os.makedirs(agent_dir, exist_ok=True)
file_path = os.path.join(agent_dir, filename)

with open(file_path, "w") as buffer:
shutil.copyfileobj(file.file, buffer)

except Exception as e:
logger.exception("Error in builder_build: %s", e)
return False

return True

@app.post("/run", response_model_exclude_none=True)
async def agent_run(req: AgentRunRequest) -> list[Event]:
Expand Down