Full agent admin via API and UI
This commit is contained in:
1 parent
5351144edf
commit
08f0668997
7 files changed
+389
-32
No files matched your search
+60
-1
@@ -32,6 +32,9 @@ class App:
|
||||
else:
|
||||
raise Exception("Horde only works with a replicate client. Please provide an API Token.")
|
||||
|
||||
# `Agent` is the kind 'basic', will be class `BasicAgent` in the future
|
||||
self.agent_classes = [Agent]
|
||||
|
||||
def sql_session(self):
|
||||
return Session(self.sql_engine)
|
||||
|
||||
@@ -82,6 +85,37 @@ class App:
|
||||
|
||||
return chat_id
|
||||
|
||||
# Updates the agent's basic fields, and applies field updates in its data
|
||||
def update_agent(self, agent_id, name=None, description=None, picture=None, data=None):
|
||||
with self.sql_session() as session:
|
||||
agent = session.execute(
|
||||
select(db.Agent).where(db.Agent.id == agent_id)
|
||||
).scalars().first()
|
||||
|
||||
if not agent:
|
||||
raise Exception(f"Agent not found with id {agent_id}")
|
||||
|
||||
summary = []
|
||||
|
||||
if name != None:
|
||||
agent.name = name
|
||||
summary.append('name')
|
||||
if description != None:
|
||||
agent.description = description
|
||||
summary.append('description')
|
||||
if picture != None:
|
||||
agent.picture = picture
|
||||
summary.append('picture')
|
||||
|
||||
if data:
|
||||
# Assign a copy to trigger a value change
|
||||
agent.data = agent.data.copy()
|
||||
agent.data.update(data)
|
||||
summary.extend([f"data.{name}" for name in data.keys()])
|
||||
|
||||
session.commit()
|
||||
print(f"Updated agent #{agent.id} fields: {summary}")
|
||||
|
||||
def get_chats(self, user_id):
|
||||
with self.sql_session() as session:
|
||||
chats = session.execute(select(db.Chat).where(db.Chat.user_id == user_id)).scalars().all()
|
||||
@@ -102,6 +136,9 @@ class App:
|
||||
"picture": agent.picture
|
||||
} for agent in agents]
|
||||
|
||||
def get_agent_kinds(self):
|
||||
return [kind.identifier for kind in self.agent_classes]
|
||||
|
||||
def delete_chat(self, chat_id):
|
||||
with self.sql_session() as session:
|
||||
session.execute(db.Membership.__table__.delete().where(db.Membership.chat_id == chat_id))
|
||||
@@ -212,6 +249,28 @@ class App:
|
||||
control = Agent.create_from_data(app, agent_id, agent.kind, agent.data)
|
||||
return control
|
||||
|
||||
def get_agent_config_fields(self, agent_id):
|
||||
with self.sql_session() as session:
|
||||
agent = session.execute(
|
||||
select(db.Agent).where(db.Agent.id == agent_id)
|
||||
).scalars().first()
|
||||
if not agent:
|
||||
raise Exception(f"Agent not found with id {agent_id}")
|
||||
|
||||
agent_class = next((it for it in self.agent_classes if it.identifier == agent.kind), None)
|
||||
if not agent_class:
|
||||
raise Exception(f"Invalid agent kind: {agent.kind}")
|
||||
|
||||
data = agent.data or {}
|
||||
fields = [{
|
||||
'name': field.name,
|
||||
'type': field.type,
|
||||
'value': data.get(field.name, field.default)
|
||||
} for field in agent_class.schema_fields]
|
||||
|
||||
return fields
|
||||
return {}
|
||||
|
||||
async def send_agent_prompt(self, agent_id, message):
|
||||
control = self.get_agent_control(agent_id)
|
||||
response = await control.prompt(message)
|
||||
@@ -241,7 +300,7 @@ class App:
|
||||
name="Intro",
|
||||
description="Introduces you to the application.",
|
||||
picture=None,
|
||||
kind="intro",
|
||||
kind="basic", # Should be 'intro'
|
||||
data={}
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user