mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Feat: Add http api to create, update, or delete agents. (#7515)
### What problem does this PR solve? Hello, we are using ragflow as a backend service, so we need to manage agents from our own frontend. So adding these http APIs to manage agents. The code logic is copied and modified from the `rm` and `save` methods in `api/apps/canvas_app.py`. btw, I found that the `save` method in `canvas_app.py` actually allows to modify an agent to an existing title, so I kept the behavior in the http api. I'm not sure if this is intentional. ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) - [x] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe):
This commit is contained in:
@ -244,3 +244,49 @@ class RAGFlow:
|
||||
result_list.append(Agent(self, data))
|
||||
return result_list
|
||||
raise Exception(res["message"])
|
||||
|
||||
def create_agent(self, title: str, dsl: dict, description: str | None = None) -> None:
|
||||
req = {
|
||||
"title": title,
|
||||
"dsl": dsl
|
||||
}
|
||||
|
||||
if description is not None:
|
||||
req["description"] = description
|
||||
|
||||
res = self.post("/agents", req)
|
||||
res = res.json()
|
||||
|
||||
if res.get("code") != 0:
|
||||
raise Exception(res["message"])
|
||||
|
||||
def update_agent(
|
||||
self,
|
||||
agent_id: str,
|
||||
title: str | None = None,
|
||||
description: str | None = None,
|
||||
dsl: dict | None = None
|
||||
) -> None:
|
||||
req = {}
|
||||
|
||||
if title is not None:
|
||||
req["title"] = title
|
||||
|
||||
if description is not None:
|
||||
req["description"] = description
|
||||
|
||||
if dsl is not None:
|
||||
req["dsl"] = dsl
|
||||
|
||||
res = self.put(f"/agents/{agent_id}", req)
|
||||
res = res.json()
|
||||
|
||||
if res.get("code") != 0:
|
||||
raise Exception(res["message"])
|
||||
|
||||
def delete_agent(self, agent_id: str) -> None:
|
||||
res = self.delete(f"/agents/{agent_id}", {})
|
||||
res = res.json()
|
||||
|
||||
if res.get("code") != 0:
|
||||
raise Exception(res["message"])
|
||||
|
||||
Reference in New Issue
Block a user