From 5cdec6465998d9fbf640f8fc463bdae469103c28 Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 28 Nov 2024 10:26:12 +0500 Subject: [PATCH 1/4] null action for chat and added instructions for the agent's thinking prompt --- .../react-agents/default-components.tsx | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx index 6614a8a30..ffa1a6f34 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx @@ -170,6 +170,21 @@ const ChatActions = () => { // await e.commit(); // }} /> + { + // await e.commit(); + // }} + /> ); }; @@ -891,6 +906,20 @@ export const InstructionsPrompt = () => { # Instructions Respond with the next action taken by your character: ${agent.name} The method/args of your response must match one of the allowed actions. + + Before choosing an action, decide if you should respond at all: + - Return null (no action) if: + * Message is clearly meant for others (unless you have crucial information) + * Your input wouldn't add value to the conversation + * The conversation is naturally concluding + * You've already responded frequently in the last few messages + + Prioritize responding when: + - You're directly mentioned or addressed + - It's a group discussion where you can contribute meaningfully + - Your personality traits are relevant to the topic + + Stay socially aware - let others speak and avoid unnecessary interruptions. `} ); From 31932d87d09a2c5dc0462d0a30ae134e8cb0a81a Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 28 Nov 2024 11:23:10 +0500 Subject: [PATCH 2/4] improve instructions prompt on when when to choose a null action in a multiagent environment and imporve conversation guidelines --- .../packages/react-agents/default-components.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx index ffa1a6f34..1e7aba674 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx @@ -912,14 +912,25 @@ export const InstructionsPrompt = () => { * Message is clearly meant for others (unless you have crucial information) * Your input wouldn't add value to the conversation * The conversation is naturally concluding - * You've already responded frequently in the last few messages + * You've already responded frequently in the last few messages (2-3 messages max) + * Multiple other agents are already actively participating Prioritize responding when: - You're directly mentioned or addressed - It's a group discussion where you can contribute meaningfully - Your personality traits are relevant to the topic - Stay socially aware - let others speak and avoid unnecessary interruptions. + Communication guidelines: + - Avoid using names in every message - only use them when: + * Directly responding to someone for the first time + * Clarifying who you're addressing in a group + * There's potential confusion about who you're talking to + - If you've been very active in the last few messages, wrap up your participation naturally + * Use phrases like "I'll let you all discuss" or simply stop responding + * Don't feel obligated to respond to every message + - Keep responses concise and natural + - Let conversations breathe - not every message needs a response + - If multiple agents are responding to the same person, step back and let others take the lead `} ); From e8ee32c3608b76d2946d27a0af7574f9a6690399 Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 28 Nov 2024 11:26:49 +0500 Subject: [PATCH 3/4] move communication guidelines to a default communication guidelines prompt --- .../react-agents/default-components.tsx | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx index 1e7aba674..5d4cf64b7 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx @@ -674,6 +674,7 @@ export const DefaultPrompts = () => { + ); }; @@ -914,23 +915,30 @@ export const InstructionsPrompt = () => { * The conversation is naturally concluding * You've already responded frequently in the last few messages (2-3 messages max) * Multiple other agents are already actively participating - + `} + + ); +}; +export const DefaultCommunicationGuidelinesPrompt = () => { + return ( + + {dedent` Prioritize responding when: - - You're directly mentioned or addressed - - It's a group discussion where you can contribute meaningfully - - Your personality traits are relevant to the topic + - You're directly mentioned or addressed + - It's a group discussion where you can contribute meaningfully + - Your personality traits are relevant to the topic Communication guidelines: - - Avoid using names in every message - only use them when: - * Directly responding to someone for the first time - * Clarifying who you're addressing in a group - * There's potential confusion about who you're talking to - - If you've been very active in the last few messages, wrap up your participation naturally - * Use phrases like "I'll let you all discuss" or simply stop responding - * Don't feel obligated to respond to every message - - Keep responses concise and natural - - Let conversations breathe - not every message needs a response - - If multiple agents are responding to the same person, step back and let others take the lead + - Avoid using names in every message - only use them when: + * Directly responding to someone for the first time + * Clarifying who you're addressing in a group + * There's potential confusion about who you're talking to + - If you've been very active in the last few messages, wrap up your participation naturally + * Use phrases like "I'll let you all discuss" or simply stop responding + * Don't feel obligated to respond to every message + - Keep responses concise and natural + - Let conversations breathe - not every message needs a response + - If multiple agents are responding to the same person, step back and let others take the lead `} ); From 72f2966b92f3c2b92cca5223577627ce63ff140f Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Fri, 29 Nov 2024 10:06:59 +0500 Subject: [PATCH 4/4] refactor: remove explicit null action and add null action schema to DefaultFormatters --- .../react-agents/default-components.tsx | 24 ++++--------------- .../packages/react-agents/runtime.ts | 7 +++++- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx index 5d4cf64b7..10c18f1bb 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/default-components.tsx @@ -170,21 +170,6 @@ const ChatActions = () => { // await e.commit(); // }} /> - { - // await e.commit(); - // }} - /> ); }; @@ -973,11 +958,12 @@ export const JsonFormatter = () => { const actionSchemas: ZodTypeAny[] = getFilteredActions(actions, conversation, thinkOpts) .map(action => makeActionSchema(action.name, action.schema)); if (actionSchemas.length >= 2) { - return z.union( - actionSchemas as [ZodTypeAny, ZodTypeAny, ...ZodTypeAny[]] - ); + return z.union([ + z.null(), + ...actionSchemas as [ZodTypeAny, ZodTypeAny, ...ZodTypeAny[]] + ]); } else if (actionSchemas.length === 1) { - return actionSchemas[0]; + return z.union([z.null(), actionSchemas[0]]); } else { return null; } diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/runtime.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/runtime.ts index 41f6aae57..d29a7784b 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/runtime.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/runtime.ts @@ -130,8 +130,13 @@ async function _generateAgentActionStepFromMessages( const completionMessage = await generativeAgent.completeJson(promptMessages, resultSchema); if (completionMessage) { const result = {} as ActionStep; + const action = (completionMessage.content as any).action as PendingActionMessage | null; + + // if the agent decided to do nothing (choose null), return an empty action step + if (action === null) { + return result; + } - const action = (completionMessage.content as any).action as PendingActionMessage; if (action) { const { method } = action; const actionHandlers = actions.filter((action) => action.name === method);