Agent class description, visible in UI

This commit is contained in:
Shivering Ocelot committed 2025-07-01 21:26:02 -05:00
1 parent e9ebb1378a
commit 6530ff0a24
4 files changed
+49 -1

No files matched your search

+6
View File
@@ -6,6 +6,11 @@ from string import Template
from inference import LlamaMessage, replicate_llama_completion from inference import LlamaMessage, replicate_llama_completion
from agent import Agent, AgentField from agent import Agent, AgentField
CLASS_DESCRIPTION = """
Description of the Conversation Agent.
Here go additional instructions for configuration, like guidelines for the different prompts.
""".strip()
chat_system_prompt_template = Template("""$role chat_system_prompt_template = Template("""$role
The first message contains information about you and a conversation that you're participating in. The first message contains information about you and a conversation that you're participating in.
Respond only with your next message in the conversation. Respond only with your next message in the conversation.
@@ -84,6 +89,7 @@ class ThreadContext:
class ConversationAgent(Agent): class ConversationAgent(Agent):
identifier = "conversation" identifier = "conversation"
description = CLASS_DESCRIPTION
schema_fields = [ schema_fields = [
AgentField('system_prompt', 'string', default="You are a friendly AI having a casual conversation with the user."), AgentField('system_prompt', 'string', default="You are a friendly AI having a casual conversation with the user."),
] ]
+11 -1
View File
@@ -155,12 +155,22 @@ class App:
"id": agent.id, "id": agent.id,
"name": agent.name, "name": agent.name,
"description": agent.description, "description": agent.description,
"picture": agent.picture "picture": agent.picture,
"kind": agent.kind,
} for agent in agents] } for agent in agents]
def get_agent_kinds(self): def get_agent_kinds(self):
return [kind.identifier for kind in self.agent_classes] return [kind.identifier for kind in self.agent_classes]
def get_agent_kind_info(self, kind):
agent_class = next((it for it in self.agent_classes if it.identifier == kind), None)
if agent_class is None:
raise Exception(f"invalid agent kind: {kind}")
return {
"name": agent_class.identifier,
"description": getattr(agent_class, 'description', None),
}
def delete_chat(self, chat_id): def delete_chat(self, chat_id):
with self.sql_session() as session: with self.sql_session() as session:
session.execute(db.Membership.__table__.delete().where(db.Membership.chat_id == chat_id)) session.execute(db.Membership.__table__.delete().where(db.Membership.chat_id == chat_id))
+3
View File
@@ -146,6 +146,9 @@ def start_server(app):
elif action == "get-agent-kinds": elif action == "get-agent-kinds":
await send({'message': "agents retrieved", 'kinds': app.get_agent_kinds(), 'nonce': nonce}) await send({'message': "agents retrieved", 'kinds': app.get_agent_kinds(), 'nonce': nonce})
elif action == "get-agent-kind-info":
await send({'message': "agent kind retrieved", 'info': app.get_agent_kind_info(body['kind']), 'nonce': nonce})
elif action == "get-agents": elif action == "get-agents":
await send({'message': "agents retrieved", 'agents': app.get_agents(user_id), 'nonce': nonce}) await send({'message': "agents retrieved", 'agents': app.get_agents(user_id), 'nonce': nonce})
+29
View File
@@ -25,14 +25,36 @@ class AgentScreen extends StatefulWidget {
class _AgentScreenState extends State<AgentScreen> { class _AgentScreenState extends State<AgentScreen> {
String? _title; String? _title;
final TextEditingController nameController = TextEditingController(); final TextEditingController nameController = TextEditingController();
String description = "";
List<ConfigField> configFields = []; List<ConfigField> configFields = [];
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_loadAgentInfo();
_loadConfigFields(); _loadConfigFields();
} }
void _loadAgentInfo() async {
final agentsResponse = await Backend.sendAction('get-agents', {});
var agentEntry = null;
for (var entry in agentsResponse['agents']) {
if (entry['id'] == widget.agentId) {
agentEntry = entry;
}
}
if (agentEntry == null) {
print("Agent ${widget.agentId} not found in agents list");
return;
}
final kindResponse = await Backend.sendAction('get-agent-kind-info', {'kind': agentEntry['kind']});
setState(() {
description = kindResponse['info']['description'];
});
}
void _loadConfigFields() async { void _loadConfigFields() async {
final response = await Backend.sendAction('get-agent-config-fields', {'agentId': widget.agentId}); final response = await Backend.sendAction('get-agent-config-fields', {'agentId': widget.agentId});
setState(() { setState(() {
@@ -77,6 +99,13 @@ class _AgentScreenState extends State<AgentScreen> {
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: Column( child: Column(
children: [ children: [
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(description),
)
),
ListView.builder( ListView.builder(
shrinkWrap: true, shrinkWrap: true,
itemCount: configFields.length, itemCount: configFields.length,