Skip to content

Commit 7906703

Browse files
Merge pull request #397 from MervinPraison/develop
Enhance Agent Tool Execution Logging and Debugging
2 parents f3c1516 + eb7b3a2 commit 7906703

11 files changed

Lines changed: 63 additions & 763 deletions

File tree

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.11-slim
22
WORKDIR /app
33
COPY . .
4-
RUN pip install flask praisonai==2.0.77 gunicorn markdown
4+
RUN pip install flask praisonai==2.0.78 gunicorn markdown
55
EXPOSE 8080
66
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]

docs/api/praisonai/deploy.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h2 id="raises">Raises</h2>
110110
file.write(&#34;FROM python:3.11-slim\n&#34;)
111111
file.write(&#34;WORKDIR /app\n&#34;)
112112
file.write(&#34;COPY . .\n&#34;)
113-
file.write(&#34;RUN pip install flask praisonai==2.0.77 gunicorn markdown\n&#34;)
113+
file.write(&#34;RUN pip install flask praisonai==2.0.78 gunicorn markdown\n&#34;)
114114
file.write(&#34;EXPOSE 8080\n&#34;)
115115
file.write(&#39;CMD [&#34;gunicorn&#34;, &#34;-b&#34;, &#34;0.0.0.0:8080&#34;, &#34;api:app&#34;]\n&#39;)
116116

praisonai.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Praisonai < Formula
33

44
desc "AI tools for various AI applications"
55
homepage "https://github.com/MervinPraison/PraisonAI"
6-
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/2.0.77.tar.gz"
6+
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/2.0.78.tar.gz"
77
sha256 "1828fb9227d10f991522c3f24f061943a254b667196b40b1a3e4a54a8d30ce32" # Replace with actual SHA256 checksum
88
license "MIT"
99

praisonai/deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def create_dockerfile(self):
5656
file.write("FROM python:3.11-slim\n")
5757
file.write("WORKDIR /app\n")
5858
file.write("COPY . .\n")
59-
file.write("RUN pip install flask praisonai==2.0.77 gunicorn markdown\n")
59+
file.write("RUN pip install flask praisonai==2.0.78 gunicorn markdown\n")
6060
file.write("EXPOSE 8080\n")
6161
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
6262

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "PraisonAI"
3-
version = "2.0.77"
3+
version = "2.0.78"
44
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human-agent collaboration."
55
readme = "README.md"
66
license = ""
@@ -12,7 +12,7 @@ dependencies = [
1212
"rich>=13.7",
1313
"markdown>=3.5",
1414
"pyparsing>=3.0.0",
15-
"praisonaiagents>=0.0.62",
15+
"praisonaiagents>=0.0.63",
1616
"python-dotenv>=0.19.0",
1717
"instructor>=1.3.3",
1818
"PyYAML>=6.0",
@@ -84,7 +84,7 @@ autogen = ["pyautogen>=0.2.19", "praisonai-tools>=0.0.7", "crewai"]
8484

8585
[tool.poetry]
8686
name = "PraisonAI"
87-
version = "2.0.77"
87+
version = "2.0.78"
8888
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human–agent collaboration."
8989
authors = ["Mervin Praison"]
9090
license = ""
@@ -102,7 +102,7 @@ python = ">=3.10,<3.13"
102102
rich = ">=13.7"
103103
markdown = ">=3.5"
104104
pyparsing = ">=3.0.0"
105-
praisonaiagents = ">=0.0.62"
105+
praisonaiagents = ">=0.0.63"
106106
python-dotenv = ">=0.19.0"
107107
instructor = ">=1.3.3"
108108
PyYAML = ">=6.0"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from praisonaiagents import Agent
2+
from praisonaiagents.tools import internet_search
3+
4+
agent = Agent(
5+
instructions="You are a Wikipedia Agent",
6+
tools=[internet_search],
7+
llm="anthropic/claude-3-7-sonnet-20250219",
8+
verbose=10
9+
)
10+
agent.start("history of AI in 1 line")

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -438,20 +438,29 @@ def get_response(
438438
function_name = tool_call["function"]["name"]
439439
arguments = json.loads(tool_call["function"]["arguments"])
440440

441-
if verbose:
442-
display_tool_call(f"Agent {agent_name} is calling function '{function_name}' with arguments: {arguments}", console=console)
443-
441+
logging.debug(f"[TOOL_EXEC_DEBUG] About to execute tool {function_name} with args: {arguments}")
444442
tool_result = execute_tool_fn(function_name, arguments)
443+
logging.debug(f"[TOOL_EXEC_DEBUG] Tool execution result: {tool_result}")
445444

446-
if tool_result:
447-
if verbose:
448-
display_tool_call(f"Function '{function_name}' returned: {tool_result}", console=console)
445+
if verbose:
446+
display_message = f"Agent {agent_name} called function '{function_name}' with arguments: {arguments}\n"
447+
if tool_result:
448+
display_message += f"Function returned: {tool_result}"
449+
logging.debug(f"[TOOL_EXEC_DEBUG] Display message with result: {display_message}")
450+
else:
451+
display_message += "Function returned no output"
452+
logging.debug("[TOOL_EXEC_DEBUG] Tool returned no output")
453+
454+
logging.debug(f"[TOOL_EXEC_DEBUG] About to display tool call with message: {display_message}")
455+
display_tool_call(display_message, console=console)
456+
449457
messages.append({
450458
"role": "tool",
451459
"tool_call_id": tool_call["id"],
452460
"content": json.dumps(tool_result)
453461
})
454462
else:
463+
logging.debug("[TOOL_EXEC_DEBUG] Verbose mode off, not displaying tool call")
455464
messages.append({
456465
"role": "tool",
457466
"tool_call_id": tool_call["id"],
@@ -923,14 +932,15 @@ async def get_response_async(
923932
function_name = tool_call.function.name
924933
arguments = json.loads(tool_call.function.arguments)
925934

926-
if verbose:
927-
display_tool_call(f"Agent {agent_name} is calling function '{function_name}' with arguments: {arguments}", console=console)
928-
929935
tool_result = await execute_tool_fn(function_name, arguments)
930936

931-
if tool_result:
932-
if verbose:
933-
display_tool_call(f"Function '{function_name}' returned: {tool_result}", console=console)
937+
if verbose:
938+
display_message = f"Agent {agent_name} called function '{function_name}' with arguments: {arguments}\n"
939+
if tool_result:
940+
display_message += f"Function returned: {tool_result}"
941+
else:
942+
display_message += "Function returned no output"
943+
display_tool_call(display_message, console=console)
934944
messages.append({
935945
"role": "tool",
936946
"tool_call_id": tool_call.id,

src/praisonai-agents/praisonaiagents/main.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ async def execute_callback(display_type: str, **kwargs):
8686
def _clean_display_content(content: str, max_length: int = 20000) -> str:
8787
"""Helper function to clean and truncate content for display."""
8888
if not content or not str(content).strip():
89+
logging.debug(f"Empty content received in _clean_display_content: {repr(content)}")
8990
return ""
9091

9192
content = str(content)
@@ -174,11 +175,14 @@ def display_instruction(message: str, console=None, agent_name: str = None, agen
174175
console.print(Panel.fit(Text(message, style="bold blue"), title="Instruction", border_style="cyan"))
175176

176177
def display_tool_call(message: str, console=None):
178+
logging.debug(f"display_tool_call called with message: {repr(message)}")
177179
if not message or not message.strip():
180+
logging.debug("Empty message in display_tool_call, returning early")
178181
return
179182
if console is None:
180183
console = Console()
181184
message = _clean_display_content(str(message))
185+
logging.debug(f"Cleaned message in display_tool_call: {repr(message)}")
182186

183187
# Execute callback if registered
184188
if 'tool_call' in sync_display_callbacks:
@@ -202,7 +206,8 @@ def display_error(message: str, console=None):
202206

203207
def display_generating(content: str = "", start_time: Optional[float] = None):
204208
if not content or not str(content).strip():
205-
return Panel("", title="", border_style="green")
209+
logging.debug("Empty content in display_generating, returning early")
210+
return None
206211

207212
elapsed_str = ""
208213
if start_time is not None:
@@ -293,11 +298,14 @@ async def adisplay_instruction(message: str, console=None, agent_name: str = Non
293298

294299
async def adisplay_tool_call(message: str, console=None):
295300
"""Async version of display_tool_call."""
301+
logging.debug(f"adisplay_tool_call called with message: {repr(message)}")
296302
if not message or not message.strip():
303+
logging.debug("Empty message in adisplay_tool_call, returning early")
297304
return
298305
if console is None:
299306
console = Console()
300307
message = _clean_display_content(str(message))
308+
logging.debug(f"Cleaned message in adisplay_tool_call: {repr(message)}")
301309

302310
if 'tool_call' in async_display_callbacks:
303311
await async_display_callbacks['tool_call'](message=message)
@@ -321,7 +329,8 @@ async def adisplay_error(message: str, console=None):
321329
async def adisplay_generating(content: str = "", start_time: Optional[float] = None):
322330
"""Async version of display_generating."""
323331
if not content or not str(content).strip():
324-
return Panel("", title="", border_style="green")
332+
logging.debug("Empty content in adisplay_generating, returning early")
333+
return None
325334

326335
elapsed_str = ""
327336
if start_time is not None:

src/praisonai-agents/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "praisonaiagents"
7-
version = "0.0.62"
7+
version = "0.0.63"
88
description = "Praison AI agents for completing complex tasks with Self Reflection Agents"
99
authors = [
1010
{ name="Mervin Praison" }

0 commit comments

Comments
 (0)