langchain.agents.self_ask_with_search.base.create_self_ask_with_search_agent¶

langchain.agents.self_ask_with_search.base.create_self_ask_with_search_agent(llm: BaseLanguageModel, tools: Sequence[BaseTool], prompt: BasePromptTemplate) Runnable[source]¶

Create an agent that uses self-ask with search prompting.

Examples

from langchain import hub
from langchain_community.chat_models import ChatAnthropic
from langchain.agents import (
    AgentExecutor, create_self_ask_with_search_agent
)

prompt = hub.pull("hwchase17/self-ask-with-search")
model = ChatAnthropic()
tools = [...]  # Should just be one tool with name `Intermediate Answer`

agent = create_self_ask_with_search_agent(model, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)

agent_executor.invoke({"input": "hi"})
Parameters
  • llm – LLM to use as the agent.

  • tools – List of tools. Should just be of length 1, with that tool having name Intermediate Answer

  • prompt – The prompt to use, must have input keys of agent_scratchpad.

Returns

A runnable sequence representing an agent. It takes as input all the same input variables as the prompt passed in does. It returns as output either an AgentAction or AgentFinish.