Closed Pckool closed 3 hours ago
Hey @Pckool, you need to add a MessagesPlaceholder
to your prompt where the agent will inject messages:
export const claude35Sonnet = new ChatAnthropic({
modelName: 'claude-3-5-sonnet-20240620',
temperature: 0.45,
streaming: true,
anthropicApiKey: env.ANTHROPIC_API_KEY,
});
const prompt = ChatPromptTemplate.fromMessages(
[
["system", `some custom system instructions`],
["placeholder", "{messages}"],
]
);
const agent = createReactAgent({
llm: model,
tools: [
// imagine a list of tools here
],
messageModifier: prompt
});
const res = await agent.invoke({
messages: [
{ role: 'user', content: 'some random text, please do something for me AI :)'}
]
})
Please reopen if the above doesn't fix it!
Hey @jacoblee93 !
That was the first thing I tried and it throws an error saying messages
is missing. Although, I looked at the code and createReactAgent already adds this placeholder so this shouldn't be needed (and as I mentioned, this code works perfectly when using an openai model).
Here's the traces:
After that didn't work I tried formattingMessages before sending it to the react agent like so:
const agent = createReactAgent({
llm: claude35Sonnet,
tools: [
// imagine a list of tools here
],
messageModifier: () => prompt.formatMessages({ messages: cleanedMessages })
});
but that doesn't work either, the messages get lost again in the RunnableLambda scope like above
I can't reopen this issue from here, but I created another issue here adding the context above: https://github.com/langchain-ai/langgraphjs/issues/521
Found the issue, it was a silly issue with how I was creating the messages, anthropic couldn't recognize the roles I was giving. Gave the full reason in #521
Ah ok great! Glad you figured it out.
I'm using createReactAgent, and when I pass an OpenAI model it works fine, but when I pass an anthropic model, the model never get's the messages passed to the agent graph, even though it's there on the top level of the trace. Once it get's into the
RunnableLanbda
scope, themessages
property is lost somehow? The system message is still there, but the other messages passed are not. I'm on the latest version for all packages:Pics of langsmith traces below:
Here's an example of how I'm calling it: