MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / createReactAgent

Function createReactAgent

packages/components/src/agents.ts:770–796  ·  view source on GitHub ↗
({ llm, tools, prompt }: CreateReactAgentParams)

Source from the content-addressed store, hash-verified

768}
769
770export const createReactAgent = async ({ llm, tools, prompt }: CreateReactAgentParams) => {
771 const missingVariables = ['tools', 'tool_names', 'agent_scratchpad'].filter((v) => !prompt.inputVariables.includes(v))
772 if (missingVariables.length > 0) {
773 throw new Error(`Provided prompt is missing required input variables: ${JSON.stringify(missingVariables)}`)
774 }
775 const toolNames = tools.map((tool) => tool.name)
776 const partialedPrompt = await prompt.partial({
777 tools: renderTextDescription(tools),
778 tool_names: toolNames.join(', ')
779 })
780 // TODO: Add .bind to core runnable interface.
781 const llmWithStop = (llm as BaseLanguageModel).withConfig({
782 stop: ['\nObservation:']
783 })
784 const agent = RunnableSequence.from([
785 RunnablePassthrough.assign({
786 //@ts-ignore
787 agent_scratchpad: (input: { steps: AgentStep[] }) => formatLogToString(input.steps)
788 }),
789 partialedPrompt,
790 llmWithStop,
791 new ReActSingleInputOutputParser({
792 toolNames
793 })
794 ])
795 return agent
796}
797
798class ReActSingleInputOutputParser extends AgentActionOutputParser {
799 lc_namespace = ['langchain', 'agents', 'react']

Callers 2

runMethod · 0.90
runMethod · 0.90

Calls 2

renderTextDescriptionFunction · 0.85
stringifyMethod · 0.80

Tested by

no test coverage detected