diff --git a/app.py b/app.py index ef1a37e469f3..d80d12d1d8bc 100644 --- a/app.py +++ b/app.py @@ -76,22 +76,22 @@ class ToggleCommandPayload(BaseModel): class Prompt(BaseModel): prompt: str -@app.get("/api/provider") +@app.get("/api/provider", tags=["Provider"]) async def get_providers(): providers = CFG.get_providers() return {"providers": providers} -@app.post("/api/agent") +@app.post("/api/agent", tags=["Agent"]) async def add_agent(agent_name: AgentName) -> Dict[str, str]: agent_info = CFG.add_agent(agent_name.agent_name) return {"message": "Agent added", "agent_file": agent_info['agent_file']} -@app.put("/api/agent/{agent_name}") +@app.put("/api/agent/{agent_name}", tags=["Agent"]) async def rename_agent(agent_name: str, new_name: AgentNewName) -> ResponseMessage: CFG.rename_agent(agent_name, new_name.new_name) return ResponseMessage(message=f"Agent {agent_name} renamed to {new_name.new_name}.") -@app.delete("/api/agent/{agent_name}") +@app.delete("/api/agent/{agent_name}", tags=["Agent"]) async def delete_agent(agent_name: str) -> ResponseMessage: result, status_code = CFG.delete_agent(agent_name) if status_code == 200: @@ -99,45 +99,45 @@ async def delete_agent(agent_name: str) -> ResponseMessage: else: raise HTTPException(status_code=status_code, detail=result["message"]) -@app.get("/api/agent") +@app.get("/api/agent", tags=["Agent"]) async def get_agents(): agents = CFG.get_agents() return {"agents": agents} -@app.get("/api/agent/{agent_name}") +@app.get("/api/agent/{agent_name}", tags=["Agent"]) async def get_agent_config(agent_name: str): agent_config = CFG.get_agent_config(agent_name) return {"agent": agent_config} -@app.get("/api/{agent_name}/chat") +@app.get("/api/{agent_name}/chat", tags=["Agent"]) async def get_chat_history(agent_name: str): chat_history = CFG.get_chat_history(agent_name) return {"chat_history": chat_history} -@app.delete("/api/agent/{agent_name}/memory") +@app.delete("/api/agent/{agent_name}/memory", tags=["Agent"]) async def wipe_agent_memories(agent_name: str) -> ResponseMessage: CFG.wipe_agent_memories(agent_name) return ResponseMessage(message=f"Memories for agent {agent_name} deleted.") -@app.post("/api/agent/{agent_name}/instruct") +@app.post("/api/agent/{agent_name}/instruct", tags=["Agent"]) async def instruct(agent_name: str, prompt: Prompt): agent = AgentLLM(agent_name) response = agent.run(prompt.prompt, max_context_tokens=500, long_term_access=False) return {"response": str(response)} -@app.post("/api/agent/{agent_name}/chat") +@app.post("/api/agent/{agent_name}/chat", tags=["Agent"]) async def chat(agent_name: str, prompt: Prompt): agent = AgentLLM(agent_name) response = agent.run(prompt.prompt, max_context_tokens=500, long_term_access=False) return {"response": str(response)} -@app.get("/api/agent/{agent_name}/command") +@app.get("/api/agent/{agent_name}/command", tags=["Agent"]) async def get_commands(agent_name: str): commands = Commands(agent_name) available_commands = commands.get_available_commands() return {"commands": available_commands} -@app.patch("/api/agent/{agent_name}/command") +@app.patch("/api/agent/{agent_name}/command", tags=["Agent"]) async def toggle_command(agent_name: str, payload: ToggleCommandPayload) -> ResponseMessage: try: if payload.command_name == "*": @@ -154,7 +154,7 @@ async def toggle_command(agent_name: str, payload: ToggleCommandPayload) -> Resp except Exception as e: raise HTTPException(status_code=500, detail=f"Error enabling all commands for agent '{agent_name}': {str(e)}") -@app.post("/api/agent/{agent_name}/task") +@app.post("/api/agent/{agent_name}/task", tags=["Agent"]) async def toggle_task_agent(agent_name: str, objective: Objective) -> ResponseMessage: if agent_name not in agent_instances: if agent_name not in agent_instances: @@ -169,7 +169,7 @@ async def toggle_task_agent(agent_name: str, objective: Objective) -> ResponseMe agent_instance = agent_instances[agent_name] agent_instance.stop_running() -@app.get("/api/agent/{agent_name}/task") +@app.get("/api/agent/{agent_name}/task", tags=["Agent"]) async def get_task_output(agent_name: str) -> TaskOutput: if agent_name not in agent_instances: raise HTTPException(status_code=404, detail="Task agent not found") @@ -179,7 +179,7 @@ async def get_task_output(agent_name: str) -> TaskOutput: return TaskOutput(output=output, message="Task agent is still running") return TaskOutput(output=output) -@app.get("/api/agent/{agent_name}/task/status") +@app.get("/api/agent/{agent_name}/task/status", tags=["Agent"]) async def get_task_status(agent_name: str): if agent_name not in agent_instances: return {"status": False} @@ -187,52 +187,52 @@ async def get_task_status(agent_name: str): status = agent_instance.get_status() return {"status": status} -@app.get("/api/chain") +@app.get("/api/chain", tags=["Chain"]) async def get_chains(): chains = CFG.get_chains() return chains -@app.get("/api/chain/{chain_name}") +@app.get("/api/chain/{chain_name}", tags=["Chain"]) async def get_chain(chain_name: str): chain_data = CFG.get_chain(chain_name) return chain_data -@app.post("/api/chain") +@app.post("/api/chain", tags=["Chain"]) async def add_chain(chain_name: ChainName) -> ResponseMessage: CFG.add_chain(chain_name.chain_name) return ResponseMessage(message=f"Chain '{chain_name.chain_name}' created.") -@app.put("/api/chain/{chain_name}") +@app.put("/api/chain/{chain_name}", tags=["Chain"]) async def rename_chain(chain_name: str, new_name: ChainNewName) -> ResponseMessage: CFG.rename_chain(chain_name, new_name.new_name) return ResponseMessage(message=f"Chain '{chain_name}' renamed to '{new_name.new_name}'.") -@app.delete("/api/chain/{chain_name}") +@app.delete("/api/chain/{chain_name}", tags=["Chain"]) async def delete_chain(chain_name: str) -> ResponseMessage: CFG.delete_chain(chain_name) return ResponseMessage(message=f"Chain '{chain_name}' deleted.") -@app.post("/api/chain/{chain_name}/step") +@app.post("/api/chain/{chain_name}/step", tags=["Chain"]) async def add_step(chain_name: str, step_info: StepInfo) -> ResponseMessage: CFG.add_step(chain_name, step_info.step_number, step_info.prompt_type, step_info.prompt) return {"message": f"Step {step_info.step_number} added to chain '{chain_name}'."} -@app.put("/api/chain/{chain_name}/step") +@app.put("/api/chain/{chain_name}/step", tags=["Chain"]) async def update_step(chain_name: str, chain_step: ChainStep) -> ResponseMessage: CFG.update_step(chain_name, chain_step.step_number, chain_step.agent_name, chain_step.prompt_type, chain_step.prompt) return {"message": f"Step {chain_step.step_number} updated for chain '{chain_name}'."} -@app.patch("/api/chain/{chain_name}/step/move") +@app.patch("/api/chain/{chain_name}/step/move", tags=["Chain"]) async def move_step(chain_name: str, chain_step_new_info: ChainStepNewInfo) -> ResponseMessage: CFG.move_step(chain_name, chain_step_new_info.old_step_number, chain_step_new_info.new_step_number, chain_step_new_info.prompt_type) return {"message": f"Step {chain_step_new_info.old_step_number} moved to {chain_step_new_info.new_step_number} in chain '{chain_name}'."} -@app.delete("/api/chain/{chain_name}/step/{step_number}") +@app.delete("/api/chain/{chain_name}/step/{step_number}", tags=["Chain"]) async def delete_step(chain_name: str, step_number: int) -> ResponseMessage: CFG.delete_step(chain_name, step_number) return {"message": f"Step {step_number} deleted from chain '{chain_name}'."} -@app.post("/api/prompt") +@app.post("/api/prompt", tags=["Prompt"]) async def add_prompt(prompt_name: PromptName, prompt: Prompt) -> ResponseMessage: try: CFG.add_prompt(prompt_name.prompt_name, prompt.prompt) @@ -240,7 +240,7 @@ async def add_prompt(prompt_name: PromptName, prompt: Prompt) -> ResponseMessage except Exception as e: raise HTTPException(status_code=400, detail=str(e)) -@app.get("/api/prompt/{prompt_name}") +@app.get("/api/prompt/{prompt_name}", tags=["Prompt"], response_model=Prompt) async def get_prompt(prompt_name: str): try: prompt_content = CFG.get_prompt(prompt_name) @@ -248,12 +248,12 @@ async def get_prompt(prompt_name: str): except Exception as e: raise HTTPException(status_code=404, detail=str(e)) -@app.get("/api/prompt", response_model=PromptList) +@app.get("/api/prompt", response_model=PromptList, tags=["Prompt"]) async def get_prompts(): prompts = CFG.get_prompts() return {"prompts": prompts} -@app.delete("/api/prompt/{prompt_name}") +@app.delete("/api/prompt/{prompt_name}", tags=["Prompt"]) async def delete_prompt(prompt_name: str) -> ResponseMessage: try: CFG.delete_prompt(prompt_name) @@ -261,7 +261,7 @@ async def delete_prompt(prompt_name: str) -> ResponseMessage: except Exception as e: raise HTTPException(status_code=404, detail=str(e)) -@app.put("/api/prompt/{prompt_name}") +@app.put("/api/prompt/{prompt_name}", tags=["Prompt"]) async def update_prompt(prompt_name: str, prompt: Prompt) -> ResponseMessage: try: CFG.update_prompt(prompt_name, prompt.prompt)