Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKProvidersAnthropicAWSGoogleMicrosoftOpenAIMoreComponentsLLMsChat modelsDocument loadersDocument transformersText embedding modelsVector storesRetrieversToolsAgents and toolkitsAINetworkAirbyte Question AnsweringAmadeusAzure Cognitive ServicesClickUp Langchain ToolkitCSVDocument ComparisonGithubGitlabGmailGoogle Drive toolJiraJSONMultiOnOffice365OpenAPINatural Language APIsPandas DataframePlayWright BrowserPowerBI DatasetPythonSpark DataframeSpark SQLSQL DatabaseVectorstoreXorbitsMemoryCallbacksChat loadersComponentsAgents and toolkitsPythonOn this pagePythonThis notebook showcases an agent designed to write and execute Python code to answer a question.from langchain.agents.agent_toolkits import create_python_agentfrom langchain.tools.python.tool import PythonREPLToolfrom langchain.python import PythonREPLfrom langchain.llms.openai import OpenAIfrom langchain.agents.agent_types import AgentTypefrom langchain.chat_models import ChatOpenAIUsing ZERO_SHOT_REACT_DESCRIPTION‚ÄãThis shows how to initialize the agent using the ZERO_SHOT_REACT_DESCRIPTION agent type.agent_executor = create_python_agent(    llm=OpenAI(temperature=0, max_tokens=1000),    tool=PythonREPLTool(),    verbose=True,    agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,)Using OpenAI Functions‚ÄãThis shows how to initialize the agent using the OPENAI_FUNCTIONS agent type. Note that this is an alternative to the above.agent_executor = create_python_agent(    llm=ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613"),    tool=PythonREPLTool(),    verbose=True,    agent_type=AgentType.OPENAI_FUNCTIONS,    agent_executor_kwargs={"handle_parsing_errors": True},)Fibonacci Example‚ÄãThis example was created by John Wiseman.agent_executor.run("What is the 10th fibonacci number?")            > Entering new  chain...        Invoking: `Python_REPL` with `def fibonacci(n):        if n <= 0:
This notebook showcases an agent designed to write and execute Python code to answer a question.
This notebook showcases an agent designed to write and execute Python code to answer a question. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKProvidersAnthropicAWSGoogleMicrosoftOpenAIMoreComponentsLLMsChat modelsDocument loadersDocument transformersText embedding modelsVector storesRetrieversToolsAgents and toolkitsAINetworkAirbyte Question AnsweringAmadeusAzure Cognitive ServicesClickUp Langchain ToolkitCSVDocument ComparisonGithubGitlabGmailGoogle Drive toolJiraJSONMultiOnOffice365OpenAPINatural Language APIsPandas DataframePlayWright BrowserPowerBI DatasetPythonSpark DataframeSpark SQLSQL DatabaseVectorstoreXorbitsMemoryCallbacksChat loadersComponentsAgents and toolkitsPythonOn this pagePythonThis notebook showcases an agent designed to write and execute Python code to answer a question.from langchain.agents.agent_toolkits import create_python_agentfrom langchain.tools.python.tool import PythonREPLToolfrom langchain.python import PythonREPLfrom langchain.llms.openai import OpenAIfrom langchain.agents.agent_types import AgentTypefrom langchain.chat_models import ChatOpenAIUsing ZERO_SHOT_REACT_DESCRIPTION‚ÄãThis shows how to initialize the agent using the ZERO_SHOT_REACT_DESCRIPTION agent type.agent_executor = create_python_agent(    llm=OpenAI(temperature=0, max_tokens=1000),    tool=PythonREPLTool(),    verbose=True,    agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,)Using OpenAI Functions‚ÄãThis shows how to initialize the agent using the OPENAI_FUNCTIONS agent type. Note that this is an alternative to the above.agent_executor = create_python_agent(    llm=ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613"),    tool=PythonREPLTool(),    verbose=True,    agent_type=AgentType.OPENAI_FUNCTIONS,    agent_executor_kwargs={"handle_parsing_errors": True},)Fibonacci Example‚ÄãThis example was created by John Wiseman.agent_executor.run("What is the 10th fibonacci number?")            > Entering new  chain...        Invoking: `Python_REPL` with `def fibonacci(n):        if n <= 0: