Skip to content

Commit

Permalink
Fix self_question action logic. Pass the self_question basck to the LLM.
Browse files Browse the repository at this point in the history
  • Loading branch information
darielnoel committed Aug 9, 2024
1 parent 51d1db7 commit ec32e9f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/agents/baseAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AGENT_STATUS_enum } from '../utils/enums';


class BaseAgent {
constructor({ name, role, goal, background, tools, llmConfig = {}, maxIterations = 10 }) {
constructor({ name, role, goal, background, tools, llmConfig = {}, maxIterations = 10, forceFinalAnswer = true }) {
this.id = uuidv4();
this.name = name;
this.role = role;
Expand All @@ -21,6 +21,7 @@ class BaseAgent {
...llmConfig
};
this.llmSystemMessage = null;
this.forceFinalAnswer = forceFinalAnswer;
}

setStore(store) {
Expand Down
13 changes: 11 additions & 2 deletions src/agents/reactChampionAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class ReactChampionAgent extends BaseAgent {
try {
_self.handleIterationStart({agent: _self, task, iterations, maxAgentIterations});

// Check if we need to force the final answer
if (_self.forceFinalAnswer && iterations === maxAgentIterations - 2) {
feedbackMessage = "We don't have more time to keep looking for the answer. Please use all the information you have gathered until now and give the finalAnswer right away.";
}

// pure function that returns the result of the agent thinking
const thinkingResult = await this.executeThinking(_self, task, ExecutableAgent, feedbackMessage);
// sometimes the LLM does not returns a valid JSON object so we try to sanitize the output here
Expand Down Expand Up @@ -323,13 +328,17 @@ class ReactChampionAgent extends BaseAgent {

handleThought({agent, task, parsedLLMOutput}) {
agent.store.getState().handleAgentThought({agent, task, output: parsedLLMOutput});
const feedbackMessage = "Your toughts are great, let's keep going.";
let feedbackMessage = "Your toughts are great, let's keep going.";
if(parsedLLMOutput.action === 'self_question' && parsedLLMOutput.actionInput) {
const actionAsString = typeof parsedLLMOutput.actionInput == 'object' ? JSON.stringify(parsedLLMOutput.actionInput) : parsedLLMOutput.actionInput;
feedbackMessage = "Awesome, please answer yourself the question: " + actionAsString;
}
return feedbackMessage;
}

handleSelfQuestion({agent, task, parsedLLMOutput}) {
agent.store.getState().handleAgentSelfQuestion({agent, task, output: parsedLLMOutput});
const feedbackMessage = "Awesome please answer yourself the question";
const feedbackMessage = "Awesome, please answer yourself the question";
return feedbackMessage;
}

Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class Agent {
get llmSystemMessage() {
return this.agentInstance.llmSystemMessage;
}
get forceFinalAnswer() {
return this.agentInstance.forceFinalAnswer;
}
}
class Task {
constructor({ title = '', description, expectedOutput, agent, isDeliverable = false }) {
Expand Down

0 comments on commit ec32e9f

Please sign in to comment.