Add messages support to runAgent for multi-turn bot conversations (#23395)
- Extend `runAgent` so callers can pass either a one-shot prompt or a multi-turn messages array (user / assistant text), matching AI SDK’s XOR shape — for Slack/Discord/Teams bots that need thread history. - Enforce exactly one of prompt | messages in AgentRunService; map messages 1:1 to AI SDK ModelMessages in AgentAsyncExecutorService - Update shared types, GraphQL/SDK inputs, docs (skills-and-agents), and regenerate metadata clients; existing prompt-only callers stay unchanged <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/twentyhq/twenty/pull/23395?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
This commit is contained in:
@@ -68,6 +68,42 @@ describe('runAgent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('POSTs messages when provided instead of prompt', async () => {
|
||||
const payload = {
|
||||
result: { response: 'done' },
|
||||
error: null,
|
||||
success: true,
|
||||
};
|
||||
|
||||
fetchSpy.mockResolvedValue(
|
||||
new Response(JSON.stringify({ data: { runAgent: payload } }), {
|
||||
status: 200,
|
||||
}),
|
||||
);
|
||||
|
||||
const messages = [
|
||||
{ role: 'user' as const, content: 'Hello' },
|
||||
{ role: 'assistant' as const, content: 'Hi' },
|
||||
{ role: 'user' as const, content: 'Status?' },
|
||||
];
|
||||
|
||||
const result = await runAgent({
|
||||
agentUniversalIdentifier: 'agent-uid',
|
||||
messages,
|
||||
});
|
||||
|
||||
expect(result).toEqual(payload);
|
||||
|
||||
const sentBody = JSON.parse(fetchSpy.mock.calls[0][1]?.body as string);
|
||||
|
||||
expect(sentBody.variables).toEqual({
|
||||
input: {
|
||||
agentUniversalIdentifier: 'agent-uid',
|
||||
messages,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('surfaces GraphQL errors as a regular Error', async () => {
|
||||
fetchSpy.mockResolvedValue(
|
||||
new Response(
|
||||
|
||||
Reference in New Issue
Block a user