Logging tool calls and results helps you keep track of what your tools do and what they return. This makes it easier to find problems and understand how your system works.
Logging tool calls and results in Agentic AI
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
Agentic AI
log_tool_call(tool_name, input_parameters) log_tool_result(tool_name, result_data)
log_tool_call records the tool name and what inputs it received.
log_tool_result records the output or result from the tool.
Examples
Agentic AI
log_tool_call("BackupTool", {"path": "/data"}) log_tool_result("BackupTool", "Success")
Agentic AI
log_tool_call("DeployTool", {"version": "1.2.3"}) log_tool_result("DeployTool", {"status": "failed", "error": "Timeout"})
Sample Model
This example shows logging a tool call and its result for a tool named TestTool.
Agentic AI
log_tool_call("TestTool", {"input": "test data"}) log_tool_result("TestTool", "Output OK")
Important Notes
Always log both the call and the result to have a complete picture.
Use clear and consistent names for tools to avoid confusion.
Store logs in a safe place where you can easily search and review them.
Summary
Logging tool calls and results helps track what tools do and their outputs.
This practice is useful for debugging, monitoring, and auditing.
Use simple functions to log inputs and outputs clearly and consistently.
Practice
1. What is the main purpose of logging tool calls and results in DevOps?
easy
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]
Hint: Logging means recording tool actions and outputs clearly [OK]
Common Mistakes:
- Thinking logging speeds up tools
- Believing logging hides errors
- Assuming logging reduces log file size
2. Which of the following is the correct way to log a tool call and its result in a simple Python function?
easy
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]
Hint: Use f-strings and print() to log calls and results [OK]
Common Mistakes:
- Not using f-string for variable insertion
- Printing literal variable names instead of values
- Returning string instead of printing
3. Given the code below, what will be the output?
def log_call(tool, result):
print(f"Calling {tool}...")
print(f"Result: {result}")
log_call('BackupTool', 'Success')medium
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]
Hint: Read print lines carefully and substitute variables [OK]
Common Mistakes:
- Confusing variable names with strings
- Expecting output on one line
- Thinking print syntax is wrong
4. What is wrong with this logging function?
def log_call(tool, result):
print("Calling tool...")
print("Result: result")medium
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]
Hint: Use f-strings to print variable values, not names [OK]
Common Mistakes:
- Forgetting f before string
- Using quotes around variable names
- Thinking print must be replaced by return
5. You want to log multiple tool calls and their results in a list, showing each call and result clearly. Which code snippet correctly logs all calls from the list
calls = [('ToolA', 'OK'), ('ToolB', 'Fail'), ('ToolC', 'OK')]?hard
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]
Hint: Unpack tuples and use f-strings to log each call [OK]
Common Mistakes:
- Not unpacking tuples correctly
- Printing variable names as strings
- Missing f-string for variable insertion
