Replies: 1 comment 2 replies
-
Hey @exil0867! I'm here to help you with any bugs, questions, or contributions you have. Let's tackle this issue together! To ensure that the
Here's an example of how you can structure your workflow: // Define the function for getting the current date
function getCurrentDate(state) {
// Logic to get the current date
const currentDate = new Date().toISOString().split('T')[0]; // Example date
state.messages.push({ content: `Current date is ${currentDate}` });
return state;
}
// Define the function for scheduling an appointment
function scheduleAppointment(state) {
// Logic to schedule an appointment
state.messages.push({ content: "Appointment scheduled" });
return state;
}
// Create the workflow
const workflow = new StateGraph(MessagesAnnotation)
.addNode('agent', callModel)
.addEdge(START, 'agent')
.addNode('tools', this.toolNode)
.addEdge('tools', 'agent')
.addNode('get_date', getCurrentDate)
.addNode('schedule', scheduleAppointment)
.addConditionalEdges('agent', routeMessage)
.addConditionalEdges('get_date', (state) => 'continue', { 'continue': 'schedule' })
.addConditionalEdges('schedule', (state) => 'end', { 'end': END });
// Modify the routeMessage function to handle the new sequence
function routeMessage(state) {
const { messages } = state;
const lastMessage = messages[messages.length - 1];
if (!lastMessage?.tool_calls?.length) {
return END;
}
if (lastMessage.tool_calls.includes('scheduleAppointment')) {
return 'get_date';
}
return 'tools';
} This setup ensures that when the agent decides to schedule an appointment, it first routes to the Regarding embedding the current date in the initial system prompt, it might not work as expected because the LLM may not consistently use the provided date over its internal knowledge. Using a structured workflow as shown above ensures the correct sequence of tool calls. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
-
I have a ReAct agent and I'm struggling to get it to call tools in a sequential way.
Here is my issue:
I have a tool responsible for scheduling appointments, it expects
appointmentDate
argument, however, without triggering theget_current_date
tool, it never gets the date right because the appointment date will be based on the LLMs outdated date. Passing the date tool is not enough, it will be a hit or miss, sometimes it forgets to call it before the appointment tool.I've been trying to force date call right before the appointment call and I've had no luck.
This is how my workflow looks:
How can I make it work this way:
get_current_date
toolscheduleAppointment
tool where it'sappointmentDate
argument will be the next Monday from the current date.Is there any way to achieve this? I know that probably needs an additional node where appointment calls are routed to it, but i can't figure out how to write it.
I also have no idea why embedding the current date in the initial system prompt does not work. The LLM would still use it's own outdated date.
Beta Was this translation helpful? Give feedback.
All reactions