Update some edge cases and usability of create agent flow

- Use the slug to determine which agent to PATCH
- Make the agent creation form multi-step to streamline the process
This commit is contained in:
sabaimran 2024-10-14 14:07:23 -07:00
parent 8ff13e4cf6
commit 81aa1b5589
4 changed files with 643 additions and 482 deletions

File diff suppressed because it is too large Load diff

View file

@ -696,10 +696,12 @@ class AgentAdapters:
files: List[str], files: List[str],
input_tools: List[str], input_tools: List[str],
output_modes: List[str], output_modes: List[str],
slug: Optional[str] = None,
): ):
chat_model_option = await ChatModelOptions.objects.filter(chat_model=chat_model).afirst() chat_model_option = await ChatModelOptions.objects.filter(chat_model=chat_model).afirst()
agent, created = await Agent.objects.filter(name=name, creator=user).aupdate_or_create( # Slug will be None for new agents, which will trigger a new agent creation with a generated, immutable slug
agent, created = await Agent.objects.filter(slug=slug, creator=user).aupdate_or_create(
defaults={ defaults={
"name": name, "name": name,
"creator": user, "creator": user,

View file

@ -35,6 +35,7 @@ class ModifyAgentBody(BaseModel):
files: Optional[List[str]] = [] files: Optional[List[str]] = []
input_tools: Optional[List[str]] = [] input_tools: Optional[List[str]] = []
output_modes: Optional[List[str]] = [] output_modes: Optional[List[str]] = []
slug: Optional[str] = None
@api_agents.get("", response_class=Response) @api_agents.get("", response_class=Response)
@ -192,6 +193,7 @@ async def create_agent(
body.files, body.files,
body.input_tools, body.input_tools,
body.output_modes, body.output_modes,
body.slug,
) )
agents_packet = { agents_packet = {
@ -233,7 +235,7 @@ async def update_agent(
status_code=400, status_code=400,
) )
selected_agent = await AgentAdapters.aget_agent_by_name(body.name, user) selected_agent = await AgentAdapters.aget_agent_by_slug(body.slug, user)
if not selected_agent: if not selected_agent:
return Response( return Response(
@ -253,6 +255,7 @@ async def update_agent(
body.files, body.files,
body.input_tools, body.input_tools,
body.output_modes, body.output_modes,
body.slug,
) )
agents_packet = { agents_packet = {

View file

@ -209,7 +209,7 @@ def chat_history(
agent_metadata = None agent_metadata = None
if conversation.agent: if conversation.agent:
if conversation.agent.privacy_level == Agent.PrivacyLevel.PRIVATE: if conversation.agent.privacy_level == Agent.PrivacyLevel.PRIVATE and conversation.agent.creator != user:
conversation.agent = None conversation.agent = None
else: else:
agent_metadata = { agent_metadata = {