Find answers from the community

Updated last month

if i am using ``` agent = ReActAgent.from_tools( [news_tool], llm=llm,verb

At a glance

The community member asked how to keep running a ReActAgent tool until it has validated 10 results. The other community members provided guidance on implementing a custom loop to achieve this. They suggested initializing a counter for valid results, creating a loop that runs until the counter reaches 10, and within the loop, creating a task for the agent, running it, and checking the output to determine if it's a valid result. They provided a pseudo-code example to illustrate the approach. However, they noted that the exact implementation may vary depending on the specific version of LlamaIndex being used and the nature of the news_tool. They recommended consulting the LlamaIndex documentation or reaching out to their community forums for more specific guidance tailored to the community member's use case.

@kapa.ai if i am using
Plain Text
     agent = ReActAgent.from_tools(
            [news_tool], llm=llm,verbose=True, memory=False, max_iterations=30,
        )
how do I keep running the tool until it has validated that I have 10 results
k
3 comments
Please stand by @robint as I search the knowledge base. I normally take about 15 seconds or so. :wave:
----------------------
To answer your question about running a ReActAgent tool until it has validated 10 results, I'll need to provide some additional context and suggestions, as the knowledge sources don't contain specific information about this exact scenario. However, I can offer some guidance based on the available information about ReActAgent in LlamaIndex.

The ReActAgent you're using is initialized with a single tool (news_tool), an LLM, and some parameters. To keep running the tool until you have 10 validated results, you'll need to implement a custom loop that checks the number of results and continues running the agent until the desired count is reached. Here's a general approach you could take:

  1. Initialize a counter for valid results.
  2. Create a loop that runs until the counter reaches 10.
  3. Within the loop, create a task for the agent and run it.
  4. Check the output of the task to determine if it's a valid result.
  5. If it's valid, increment the counter.
Here's a pseudo-code example of how you might implement this:

Plain Text
agent = ReActAgent.from_tools(
    [news_tool], llm=llm, verbose=True, memory=False, max_iterations=30,
)

valid_results = 0
while valid_results < 10:
    task = agent.create_task("Your task description here")
    response = agent.run(task.task_id)
    
    # Implement your validation logic here
    if is_valid_result(response):
        valid_results += 1
    
    print(f"Valid results: {valid_results}")

print("Finished collecting 10 valid results")


Please note that this is a simplified example, and you'll need to adapt it to your specific use case. You should implement the is_valid_result() function to check if the agent's response meets your criteria for a valid result.
It's important to mention that the exact implementation may vary depending on the specific version of LlamaIndex you're using and the nature of your news_tool. The ReActAgent implementation details can be found in the LlamaIndex documentation, but the knowledge sources don't provide specific information about running the agent in a loop as you've described.

If you need more precise guidance, you might want to consult the latest LlamaIndex documentation or reach out to their community forums for specific examples tailored to your use case.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord