When logging tool calls and results, the key metric is completeness and accuracy of logs. This means every tool call and its output should be recorded without missing or incorrect entries. This helps track what happened, when, and what the result was. It is important because it allows debugging, auditing, and understanding the system's behavior over time.
Logging tool calls and results in Agentic AI - Model Metrics & Evaluation
Start learning this pattern below
Jump into concepts and practice - no test required
For logging, a confusion matrix is not directly applicable. Instead, a log completeness matrix can be imagined:
+----------------------+---------------------+
| Expected Logs | Actual Logs |
+----------------------+---------------------+
| Tool call made | Tool call logged |
| Tool call made | Tool call missing |
| Tool call not made | No log entry |
+----------------------+---------------------+
We want all tool calls made to have matching log entries. Missing logs mean incomplete tracking.
Logging every tool call and result can slow down the system (performance cost). If logs are too sparse, debugging becomes hard. If logs are too detailed, storage and speed suffer. The tradeoff is to log enough detail to understand behavior without overwhelming resources.
Example: Logging only errors is fast but misses successful calls. Logging all calls is thorough but slower.
Good logging: Every tool call is logged with timestamp, input, output, and status. Logs are easy to search and understand.
Bad logging: Missing logs for some calls, unclear or inconsistent format, no timestamps, or logs that do not show results.
- Logging too little: Missing important calls or results.
- Logging too much: Huge logs that are hard to manage.
- Inconsistent formats: Hard to parse or analyze logs.
- Not logging errors or exceptions properly.
- Performance impact: Logging slows down the system if not optimized.
Your system logs 95% of tool calls but misses 5% randomly. Is this good? Why or why not?
Answer: This is not good because missing 5% of calls means some actions are not tracked. This can cause problems in debugging or auditing. Ideally, logging should be complete or near 100%.
Practice
Solution
Step 1: Understand the role of logging
Logging records actions and results of tools to help understand their behavior.Step 2: Identify the benefits of logging
Logging helps with debugging, monitoring, and auditing by showing what happened and when.Final Answer:
To track what tools do and their outputs for debugging and monitoring -> Option CQuick Check:
Logging = Track tool actions and outputs [OK]
- Thinking logging speeds up tools
- Believing logging hides errors
- Assuming logging reduces log file size
Solution
Step 1: Check string formatting with variables
def log_call(tool_name, result): print(f"Tool {tool_name} returned {result}") uses f-string correctly to insert variables tool_name and result.Step 2: Verify output method
def log_call(tool_name, result): print(f"Tool {tool_name} returned {result}") prints the message, which is typical for logging in simple scripts.Final Answer:
def log_call(tool_name, result): print(f"Tool {tool_name} returned {result}") -> Option DQuick Check:
Correct f-string and print used [OK]
- Not using f-string for variable insertion
- Printing literal variable names instead of values
- Returning string instead of printing
def log_call(tool, result):
print(f"Calling {tool}...")
print(f"Result: {result}")
log_call('BackupTool', 'Success')Solution
Step 1: Analyze the function calls
The function prints two lines: one with tool name, one with result.Step 2: Substitute arguments and check output
Calling 'BackupTool' and 'Success' prints exactly two lines with those values.Final Answer:
Calling BackupTool...\nResult: Success -> Option BQuick Check:
Print lines match arguments [OK]
- Confusing variable names with strings
- Expecting output on one line
- Thinking print syntax is wrong
def log_call(tool, result):
print("Calling tool...")
print("Result: result")Solution
Step 1: Check how variables are used in print
The function prints literal strings "tool" and "result" instead of variable values.Step 2: Understand correct variable usage
To print values, variables must be inside f-strings or concatenated properly.Final Answer:
It prints the variable names instead of their values -> Option AQuick Check:
Variables not interpolated in strings [OK]
- Forgetting f before string
- Using quotes around variable names
- Thinking print must be replaced by return
calls = [('ToolA', 'OK'), ('ToolB', 'Fail'), ('ToolC', 'OK')]?Solution
Step 1: Understand tuple unpacking in loop
for tool, result in calls: print(f"Tool {tool} returned {result}") correctly unpacks each tuple into tool and result variables.Step 2: Check correct f-string usage
for tool, result in calls: print(f"Tool {tool} returned {result}") uses f-string to insert variables properly in the print statement.Final Answer:
for tool, result in calls: print(f"Tool {tool} returned {result}") -> Option AQuick Check:
Tuple unpacking and f-string correct [OK]
- Not unpacking tuples correctly
- Printing variable names as strings
- Missing f-string for variable insertion
