Example "plan-and-execute" not work #21

Closed
opened 2026-02-15 17:05:33 -05:00 by yindo · 0 comments
Owner

Originally created by @zrg-team on GitHub (Apr 12, 2024).

Issues went implement "plan-and-execute"

i followed
https://github.com/langchain-ai/langgraphjs/blob/main/examples/plan-and-execute/plan-and-execute.ipynb

Input

const createAgentRunnable = async (
  llm: ChatOpenAI,
  tools: Awaited<ReturnType<typeof createAgentTools>>,
) => {
  // Get the prompt to use - you can modify this!
  const prompt = new ChatPromptTemplate({
    inputVariables: ['input', 'chat_history', 'agent_scratchpad'],
    promptMessages: [
      new SystemMessage(AGENT_PROMPT_SYSTEM_MESSAGE),
      new MessagesPlaceholder('chat_history'),
      HumanMessagePromptTemplate.fromTemplate('{input}'),
      HumanMessagePromptTemplate.fromTemplate(RESPONSE_INTRODUCT_MESSAGE_TEMPLATE),
      new MessagesPlaceholder('agent_scratchpad'),
    ],
  })
  // Construct the OpenAI Functions agent
  return await createOpenAIFunctionsAgent({
    llm,
    tools,
    prompt,
  })
}

export const createOGDeveloperAgentExecutor = async (
  data: AgentDataInput,
  services: AgentServiceInput,
) => {
  const tools = await createAgentTools(data, services)
  const agent = await createAgentRunnable(services.llm, tools)

  const agentExecutor = createAgentExecutor({
    agentRunnable: agent,
    tools: [],
  })

  return agentExecutor
}

ExecuteStep

executeStep = async (state: PlanExecuteState): Promise<Partial<PlanExecuteState>> => {
    const task = state.input
    const agentResponse = await this.agentExecutor.invoke({
      input: task,
      chat_history: state.chatHistory,
    })
    console.log('agentResponse', agentResponse)
    return { pastSteps: [task, agentResponse.agentOutcome.returnValues.output] }
  }

Error

err TypeError: Cannot read properties of undefined (reading 'returnValues')

The agentExcutor invoke response is not including "agentOutcome"

agentResponse {
  input: 'hi',
  chat_history: [
    AIMessage {
      lc_serializable: true,
      lc_kwargs: [Object],
      lc_namespace: [Array],
      content: '(Backend Developer) Sorry can not help you now. Please try again later.',
      name: undefined,
      additional_kwargs: {},
      response_metadata: {},
      tool_calls: [],
      invalid_tool_calls: []
    },
    AIMessage {
      lc_serializable: true,
      lc_kwargs: [Object],
      lc_namespace: [Array],
      content: '(Backend Developer) AI thinking ...',
      name: undefined,
      additional_kwargs: {},
      response_metadata: {},
      tool_calls: [],
      invalid_tool_calls: []
    }
  ],
  output: "I'm ready to assist you. How can I help you today?",
  intermediateSteps: []
}
Originally created by @zrg-team on GitHub (Apr 12, 2024). ## Issues went implement "plan-and-execute" i followed https://github.com/langchain-ai/langgraphjs/blob/main/examples/plan-and-execute/plan-and-execute.ipynb ## Input ``` const createAgentRunnable = async ( llm: ChatOpenAI, tools: Awaited<ReturnType<typeof createAgentTools>>, ) => { // Get the prompt to use - you can modify this! const prompt = new ChatPromptTemplate({ inputVariables: ['input', 'chat_history', 'agent_scratchpad'], promptMessages: [ new SystemMessage(AGENT_PROMPT_SYSTEM_MESSAGE), new MessagesPlaceholder('chat_history'), HumanMessagePromptTemplate.fromTemplate('{input}'), HumanMessagePromptTemplate.fromTemplate(RESPONSE_INTRODUCT_MESSAGE_TEMPLATE), new MessagesPlaceholder('agent_scratchpad'), ], }) // Construct the OpenAI Functions agent return await createOpenAIFunctionsAgent({ llm, tools, prompt, }) } export const createOGDeveloperAgentExecutor = async ( data: AgentDataInput, services: AgentServiceInput, ) => { const tools = await createAgentTools(data, services) const agent = await createAgentRunnable(services.llm, tools) const agentExecutor = createAgentExecutor({ agentRunnable: agent, tools: [], }) return agentExecutor } ``` ExecuteStep ``` executeStep = async (state: PlanExecuteState): Promise<Partial<PlanExecuteState>> => { const task = state.input const agentResponse = await this.agentExecutor.invoke({ input: task, chat_history: state.chatHistory, }) console.log('agentResponse', agentResponse) return { pastSteps: [task, agentResponse.agentOutcome.returnValues.output] } } ``` ## Error ``` err TypeError: Cannot read properties of undefined (reading 'returnValues') ``` The agentExcutor invoke response is not including "agentOutcome" ``` agentResponse { input: 'hi', chat_history: [ AIMessage { lc_serializable: true, lc_kwargs: [Object], lc_namespace: [Array], content: '(Backend Developer) Sorry can not help you now. Please try again later.', name: undefined, additional_kwargs: {}, response_metadata: {}, tool_calls: [], invalid_tool_calls: [] }, AIMessage { lc_serializable: true, lc_kwargs: [Object], lc_namespace: [Array], content: '(Backend Developer) AI thinking ...', name: undefined, additional_kwargs: {}, response_metadata: {}, tool_calls: [], invalid_tool_calls: [] } ], output: "I'm ready to assist you. How can I help you today?", intermediateSteps: [] } ```
yindo closed this issue 2026-02-15 17:05:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#21