which provide:The nth prime number (using a small subset for this example) The LLMMathChain to act as a calculatorprimes = {998: 7901, 999: 7907, 1000: 7919}class CalculatorInput(pydantic.BaseModel):    question: str = pydantic.Field()class PrimeInput(pydantic.BaseModel):    n: int = pydantic.Field()def is_prime(n: int) -> bool:    if n <= 1 or (n % 2 == 0 and n > 2):        return False    for i in range(3, int(n**0.5) + 1, 2):        if n % i == 0:            return False    return Truedef get_prime(n: int, primes: dict = primes) -> str:    return str(primes.get(int(n)))async def aget_prime(n: int, primes: dict = primes) -> str:    return str(primes.get(int(n)))tools = [    Tool(        name="GetPrime",        func=get_prime,        description="A tool that returns the `n`th prime number",        args_schema=PrimeInput,        coroutine=aget_prime,    ),    Tool.from_function(        func=llm_math_chain.run,        name="Calculator",        description="Useful for when you need to compute mathematical expressions",        args_schema=CalculatorInput,        coroutine=llm_math_chain.arun,    ),]Construct the agent. We will use the default agent type here.agent = initialize_agent(    tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)Run the iteration and perform a custom check on certain steps:question = "What is the product of the 998th, 999th and 1000th prime numbers?"for step in agent.iter(question):    if output := step.get("intermediate_step"):        action, value = output[0]        if action.tool == "GetPrime":            print(f"Checking whether {value} is prime...")            assert is_prime(int(value))        # Ask user if they want to continue        _continue = input("Should the agent continue (Y/n)?:\n")        if _continue != "Y":            break            > Entering new  chain...    I need to find the 998th, 999th and 1000th prime numbers first.    Action: GetPrime    Action Input: 998    Observation: 7901    Thought:Checking
To demonstrate the AgentExecutorIterator functionality, we will set up a problem where an Agent must:
To demonstrate the AgentExecutorIterator functionality, we will set up a problem where an Agent must: ->: which provide:The nth prime number (using a small subset for this example) The LLMMathChain to act as a calculatorprimes = {998: 7901, 999: 7907, 1000: 7919}class CalculatorInput(pydantic.BaseModel):    question: str = pydantic.Field()class PrimeInput(pydantic.BaseModel):    n: int = pydantic.Field()def is_prime(n: int) -> bool:    if n <= 1 or (n % 2 == 0 and n > 2):        return False    for i in range(3, int(n**0.5) + 1, 2):        if n % i == 0:            return False    return Truedef get_prime(n: int, primes: dict = primes) -> str:    return str(primes.get(int(n)))async def aget_prime(n: int, primes: dict = primes) -> str:    return str(primes.get(int(n)))tools = [    Tool(        name="GetPrime",        func=get_prime,        description="A tool that returns the `n`th prime number",        args_schema=PrimeInput,        coroutine=aget_prime,    ),    Tool.from_function(        func=llm_math_chain.run,        name="Calculator",        description="Useful for when you need to compute mathematical expressions",        args_schema=CalculatorInput,        coroutine=llm_math_chain.arun,    ),]Construct the agent. We will use the default agent type here.agent = initialize_agent(    tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)Run the iteration and perform a custom check on certain steps:question = "What is the product of the 998th, 999th and 1000th prime numbers?"for step in agent.iter(question):    if output := step.get("intermediate_step"):        action, value = output[0]        if action.tool == "GetPrime":            print(f"Checking whether {value} is prime...")            assert is_prime(int(value))        # Ask user if they want to continue        _continue = input("Should the agent continue (Y/n)?:\n")        if _continue != "Y":            break            > Entering new  chain...    I need to find the 998th, 999th and 1000th prime numbers first.    Action: GetPrime    Action Input: 998    Observation: 7901    Thought:Checking