Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[front] - fix(conversations): render conversations with archived agents #8900

Merged
merged 3 commits into from
Nov 26, 2024

Conversation

JulesBelveze
Copy link
Contributor

@JulesBelveze JulesBelveze commented Nov 26, 2024

Description

This PR modifies fetchWorkspaceAgentConfigurationsWithoutActions to return either active versions if they exist, or otherwise the latest versions.

This was recently introduced by #8892. The goal of #8892 was to fix #8888.

Context: we recently found out that:

return AgentConfiguration.findAll({
          where: {
            workspaceId: owner.id,
            ...(agentPrefix ? { name: { [Op.iLike]: `${agentPrefix}%` } } : {}),
            sId: agentsGetView.agentIds.filter((id) => !isGlobalAgentId(id)),
          },
          order: [["version", "DESC"]],
          ...(agentsGetView.allVersions ? {} : { limit: 1 }),
        });
      }

was causing a bunch of errors on the /participants endpoint as it was limiting to return only one agent configuration. Because of this the conversation participants were broken.

The initial fix was to retrieve all "active" agent configurations, which fixed the conversation participants issue. However, this led to not be able to retrieve conversation with an "archived" agent.

This PR ensures that we either return the active agent configuration or its latest archived version.

Risk

Low

Deploy Plan

Deploy front

…ersions are fetched

 - Modify fetchWorkspaceAgentConfigurationsWithoutActions to return either active versions if they exist, or otherwise the latest versions
 - Implement reduction logic to group agents by sId and select the correct version to return based on status and existence in the accumulator
@JulesBelveze JulesBelveze linked an issue Nov 26, 2024 that may be closed by this pull request
@JulesBelveze JulesBelveze requested a review from flvndvd November 26, 2024 09:52
@spolu
Copy link
Contributor

spolu commented Nov 26, 2024

@JulesBelveze

So that I understand correctly this was the limit: 1 change right?

So the diffs we had so far are:

https://github.com/dust-tt/dust/pull/8888/files
https://github.com/dust-tt/dust/pull/8892/files

And now this one?

Let's step back and really think through the change to make sure we have a full understanding here. To do so please update your PR description with references to previous 2 PRs what they changes what they broke and why this is guaranteed to be the right end-state 🙏

@@ -366,15 +366,35 @@ async function fetchWorkspaceAgentConfigurationsWithoutActions(
});
default:
if (typeof agentsGetView === "object" && "agentIds" in agentsGetView) {
return AgentConfiguration.findAll({
const agents = await AgentConfiguration.findAll({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit tough to not leverage the SQL query, no? Agent configurations can have hundreds or versions 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can go full sql, we're gonna hvave to go for raw sql though don't think we can use sequelize for such complicated query

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LEt's see the SQL query once you have it. Maybe we can map it to Sequelize.

@spolu
Copy link
Contributor

spolu commented Nov 26, 2024

Because of this the conversation participants were broken.

@JulesBelveze do we understand when it broke and how it broke? This query has been here for a long time no? Yet participants have been working in the past? What exactly broke them?

@JulesBelveze
Copy link
Contributor Author

@spolu I'm not sure to follow how this change was working: 99771e8

@spolu
Copy link
Contributor

spolu commented Nov 26, 2024

You mean the limit: 1 was at odd with the move to sId array I presume. Seems plausibe that it was problematic cc @philipperolet ?

Good that we're getting down to a very clear picture. Feel like we now have reached full context, which is great \o/

@spolu
Copy link
Contributor

spolu commented Nov 26, 2024

@JulesBelveze if you can add @philipperolet as reviewer this would be great to make sure we have full context on getting the good final state 🙏

Thanks for digging!

…rations

 - Implement a more efficient SQL query to directly fetch the necessary agent configurations
 - Remove the previous post-processing logic in favor of database-level aggregation and sorting
@philipperolet
Copy link
Contributor

After looking at it I concur with @JulesBelveze the query didn't work. Apologies for missing that.

It's strange that nobody noticed since it's been 2 months, but at the same time since it only impacts the fact that you don't see all the avatars on the top right of your screen in a conversation it's possible

Thanks a lot for solving this @JulesBelveze

Copy link
Contributor

@philipperolet philipperolet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. LGTM and thanks on fixing the issue from my PR moving to agentIds array 🙏
  2. however, I think the 'status:active' filter is what's breaking the preview; AFAICT, the preview is grabbing for a 'draft' ? continuing investigation there

@philipperolet
Copy link
Contributor

  1. LGTM and thanks on fixing the issue from my PR moving to agentIds array 🙏
  2. however, I think the 'status:active' filter is what's breaking the preview; AFAICT, the preview is grabbing for a 'draft' ? continuing investigation there

For reference, I'm talking about this wrt the preview broken: https://github.com/dust-tt/tasks/issues/1703

@philipperolet
Copy link
Contributor

Other topic: conversations with archived agents generate unhandled errors

=> https://dust4ai.slack.com/archives/C05F84CFP0E/p1732630658549379

@philipperolet
Copy link
Contributor

Discussed IRL:

  • @JulesBelveze proposed grouping by agentId and taking the latest version instead of status filtering
  • this should solve 2 problems mentioned above, and avoid the raw SQL query
    🙏

…uery

 - Include option to fetch all versions of agent configurations
 - Modify query to retrieve only latest versions of agent configurations using Sequelize ORM instead of raw query
Copy link
Contributor

@philipperolet philipperolet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (make sure to test)

@JulesBelveze
Copy link
Contributor Author

Tested the following:

  • conversation with multiple agents
  • conversation with delete agent
  • assistant preview

@JulesBelveze JulesBelveze merged commit e762f86 into main Nov 26, 2024
3 checks passed
@JulesBelveze JulesBelveze deleted the fix/conversation-deleted-agent branch November 26, 2024 15:26
overmode pushed a commit that referenced this pull request Nov 27, 2024
…ts (#8900)

* [front/lib/api/assistant] - fix: ensure only active or latest agent versions are fetched

 - Modify fetchWorkspaceAgentConfigurationsWithoutActions to return either active versions if they exist, or otherwise the latest versions
 - Implement reduction logic to group agents by sId and select the correct version to return based on status and existence in the accumulator

* [front/lib/api/assistant] - refactor: optimize fetching agent configurations

 - Implement a more efficient SQL query to directly fetch the necessary agent configurations
 - Remove the previous post-processing logic in favor of database-level aggregation and sorting

* [front/lib/api/assistant] - refactor: optimize agent configurations query

 - Include option to fetch all versions of agent configurations
 - Modify query to retrieve only latest versions of agent configurations using Sequelize ORM instead of raw query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Render conversation with deleted agent
4 participants