devika icon indicating copy to clipboard operation
devika copied to clipboard

Improve: Research Agent Regex Parsing

Open hjamet opened this issue 10 months ago • 7 comments

Description

Improvements

  • [x] Resolves numerous infinite loop issues caused by LLM response format errors, especially for OLLAMA models like LLAMA3.
  • [x] Significantly simplifies agent code and avoids duplication by introducing a new parent class that enables automatic response validation.

Resolved Issues

  • [x] https://github.com/stitionai/devika/issues/396
  • [ ] https://github.com/stitionai/devika/issues/347

The list may not be exhaustive.

Related Pull Requests

  • [x] https://github.com/stitionai/devika/pull/438 : Both pull requests are compatible. They aim to solve the same issue but with different approaches that can be combined.

Explanations

  1. The current version of Devika expects to receive a specific JSON or MARKDOWN response format from LLMs in order to parse them correctly. Unfortunately, LLMs (especially smaller models like LLAMA3) do not always manage to respond perfectly to this task and bury their JSON between explanations, making their response impossible to parse. This pull request aims to use REGEX for better extraction of responses from LLMs.

  2. Furthermore, in order to simplify this method and generalize it to all agents easily and without duplicating code, I propose in this pull request a new parent class for agents AgentTemplate which offers generic render & parse_answer methods that automatically extract the expected format from prompt.jinja2 and perform the expected validations. This modification significantly simplifies the code by reducing about 2/3 of the code for each agent, while avoiding repetition and limiting errors of the type "Invalid response from the model, trying again..."

For now, and as an example and test, I have only modified the RESEARCH agent, which now works perfectly with all LLMs I have tested: GPT4, CLAUDE OPUS, MISTRAL 8x7B, LLAMA3, and GEMMA. Once this pull request is validated, I am committed to adapting all the other agents in the same way.

hjamet avatar Apr 21 '24 19:04 hjamet

#469 and #438 works very well

darrassi1 avatar Apr 22 '24 22:04 darrassi1

This is a big improvement when using ollama. Hopefully it's merged soon :+1:

odeemi avatar Apr 24 '24 04:04 odeemi

can you do this for all the agents?

ARajgor avatar Apr 25 '24 09:04 ARajgor

can you do this for all the agents?

Of course ! I will fix the conflicts and extend the idea to all agents :)

hjamet avatar Apr 25 '24 10:04 hjamet

Thanx! Good job!

epem avatar Apr 26 '24 17:04 epem

still waiting to merge ....

mirek190 avatar Apr 27 '24 18:04 mirek190

Work good as it is , but if we want to pass new variable to the render function , it will throw error .

darrassi1 avatar Jun 18 '24 13:06 darrassi1