devika
devika copied to clipboard
Improve: Research Agent Regex Parsing
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
-
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.
-
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.
#469 and #438 works very well
This is a big improvement when using ollama. Hopefully it's merged soon :+1:
can you do this for all the agents?
can you do this for all the agents?
Of course ! I will fix the conflicts and extend the idea to all agents :)
Thanx! Good job!
still waiting to merge ....
Work good as it is , but if we want to pass new variable to the render function , it will throw error .