Skip to content

Commit 47cf9d4

Browse files
fix: accumulate tool results across iterations in Ollama sequential execution
- Replace hardcoded iteration threshold (3) with class constant OLLAMA_SUMMARY_ITERATION_THRESHOLD - Add proper constant definition for better maintainability and readability - Applied consistently to both sync and async methods - Addresses reviewer feedback about magic numbers - Ensures proper tool result accumulation across iterations Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
1 parent 26ad805 commit 47cf9d4

File tree

1 file changed

+5
-2
lines changed
  • src/praisonai-agents/praisonaiagents/llm

1 file changed

+5
-2
lines changed

src/praisonai-agents/praisonaiagents/llm/llm.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class LLM:
9393
# Ollama-specific prompt constants
9494
OLLAMA_TOOL_USAGE_PROMPT = "Please analyze the request and use the available tools to help answer the question. Start by identifying what information you need."
9595
OLLAMA_FINAL_ANSWER_PROMPT = "Based on the tool results above, please provide the final answer to the original question."
96+
97+
# Ollama iteration threshold for summary generation
98+
OLLAMA_SUMMARY_ITERATION_THRESHOLD = 3
9699

97100
def _log_llm_config(self, method_name: str, **config):
98101
"""Centralized debug logging for LLM configuration and parameters.
@@ -1112,7 +1115,7 @@ def get_response(
11121115

11131116
# Special handling for Ollama to prevent infinite loops
11141117
# Only generate summary after multiple iterations to allow sequential execution
1115-
if iteration_count >= 3:
1118+
if iteration_count >= self.OLLAMA_SUMMARY_ITERATION_THRESHOLD:
11161119
tool_summary = self._generate_ollama_tool_summary(accumulated_tool_results, response_text)
11171120
if tool_summary:
11181121
final_response_text = tool_summary
@@ -1865,7 +1868,7 @@ async def get_response_async(
18651868

18661869
# Special handling for Ollama to prevent infinite loops
18671870
# Only generate summary after multiple iterations to allow sequential execution
1868-
if iteration_count >= 3:
1871+
if iteration_count >= self.OLLAMA_SUMMARY_ITERATION_THRESHOLD:
18691872
tool_summary = self._generate_ollama_tool_summary(accumulated_tool_results, response_text)
18701873
if tool_summary:
18711874
final_response_text = tool_summary

0 commit comments

Comments
 (0)