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

Fix Agent_message does not load runIds anymore #6248

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions docs/src/pages/conversations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,6 @@ The `generation_tokens` event is sent when tokens are streamed as the the assist
}
```

The `agent_generation_success` event is sent once the generation has completed.

```
{
type: "agent_generation_success";
created: number;
configurationId: string;
messageId: string;
text: string;
}
```

### Other events

The `agent_message_success` event is sent once the message is fully completed and successful.
Expand Down
11 changes: 7 additions & 4 deletions front/lib/api/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export async function* runAgent(
agentMessage: AgentMessageType
): AsyncGenerator<
| AgentErrorEvent
| AgentActionsEvent
| AgentActionSpecificEvent
| AgentActionSuccessEvent
| GenerationTokensEvent
Expand Down Expand Up @@ -105,7 +104,6 @@ export async function* runMultiActionsAgentLoop(
agentMessage: AgentMessageType
): AsyncGenerator<
| AgentErrorEvent
| AgentActionsEvent
| AgentActionSpecificEvent
| AgentActionSuccessEvent
| GenerationTokensEvent
Expand Down Expand Up @@ -151,6 +149,8 @@ export async function* runMultiActionsAgentLoop(
isLegacyAgent,
});

const runIds = [];

for await (const event of loopIterationStream) {
switch (event.type) {
case "agent_error":
Expand All @@ -164,6 +164,7 @@ export async function* runMultiActionsAgentLoop(
yield event;
return;
case "agent_actions":
runIds.push(event.runId);
localLogger.info(
{
elapsed: Date.now() - now,
Expand All @@ -176,8 +177,6 @@ export async function* runMultiActionsAgentLoop(
// against the model outputing something unreasonable.
event.actions = event.actions.slice(0, MAX_ACTIONS_PER_STEP);

yield event;

const eventStreamGenerators = event.actions.map(
({ action, inputs, functionCallId, specification }, index) => {
return runAction(auth, {
Expand Down Expand Up @@ -265,12 +264,16 @@ export async function* runMultiActionsAgentLoop(
}
agentMessage.content = processedContent;
agentMessage.status = "succeeded";

runIds.push(event.runId);

yield {
type: "agent_message_success",
created: Date.now(),
configurationId: configuration.sId,
messageId: agentMessage.sId,
message: agentMessage,
runIds: runIds,
} satisfies AgentMessageSuccessEvent;
return;

Expand Down
16 changes: 2 additions & 14 deletions front/lib/api/assistant/conversation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type {
AgentActionsEvent,
AgentActionSpecificEvent,
AgentActionSuccessEvent,
AgentDisabledErrorEvent,
AgentErrorEvent,
AgentGenerationCancelledEvent,
AgentGenerationSuccessEvent,
AgentMessageErrorEvent,
AgentMessageNewEvent,
AgentMessageSuccessEvent,
Expand Down Expand Up @@ -1680,11 +1678,9 @@ async function* streamRunAgentEvents(
auth: Authenticator,
eventStream: AsyncGenerator<
| AgentErrorEvent
| AgentActionsEvent
| AgentActionSpecificEvent
| AgentActionSuccessEvent
| GenerationTokensEvent
| AgentGenerationSuccessEvent
| AgentGenerationCancelledEvent
| AgentMessageSuccessEvent,
void
Expand All @@ -1700,7 +1696,6 @@ async function* streamRunAgentEvents(
| AgentMessageSuccessEvent,
void
> {
const runIds = [];
for await (const event of eventStream) {
switch (event.type) {
case "agent_error":
Expand All @@ -1726,18 +1721,11 @@ async function* streamRunAgentEvents(
case "agent_action_success":
yield event;
break;
case "agent_actions":
runIds.push(event.runId);
break;
case "agent_generation_success":
case "agent_message_success":
// Store message in database.
runIds.push(event.runId);
await agentMessageRow.update({
runIds,
runIds: event.runIds,
});
break;

case "agent_message_success":
// Update status in database.
await agentMessageRow.update({
status: "succeeded",
Expand Down
11 changes: 1 addition & 10 deletions types/src/front/lib/api/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ export type AgentActionSuccessEvent = {
action: AgentActionType;
};

// Event sent once the generation is completed.
export type AgentGenerationSuccessEvent = {
type: "agent_generation_success";
created: number;
configurationId: string;
messageId: string;
text: string;
runId: string;
};

// Event sent to stop the generation.
export type AgentGenerationCancelledEvent = {
type: "agent_generation_cancelled";
Expand All @@ -107,6 +97,7 @@ export type AgentMessageSuccessEvent = {
configurationId: string;
messageId: string;
message: AgentMessageType;
runIds: string[];
};

export type AgentActionsEvent = {
Expand Down
Loading