0
0
Agentic_aiml~20 mins

Tool permission boundaries in Agentic Ai - ML Experiment: Train & Evaluate

Choose your learning style8 modes available
Experiment - Tool permission boundaries
Problem:You have an AI agent that can use multiple tools to complete tasks. Currently, the agent has full access to all tools without restrictions.
Current Metrics:Agent completes 95% of tasks but sometimes uses tools inappropriately, causing errors or security risks.
Issue:The agent lacks permission boundaries, leading to misuse of tools and potential unsafe actions.
Your Task
Implement permission boundaries so the agent only uses allowed tools for specific tasks, reducing errors and improving safety while maintaining at least 90% task completion accuracy.
You cannot remove any tools from the system.
You must keep the agent's ability to choose tools dynamically.
The solution must be implemented in the agent's decision logic.
Hint 1
Hint 2
Hint 3
Solution
Agentic_ai
class Agent:
    def __init__(self):
        self.tools = {
            'search': self.search_tool,
            'calculator': self.calculator_tool,
            'file_access': self.file_access_tool
        }
        # Define permission boundaries: which tools can be used for which tasks
        self.permission_boundaries = {
            'data_query': ['search'],
            'math_problem': ['calculator'],
            'file_management': ['file_access']
        }

    def search_tool(self, query):
        return f"Searching for {query}"

    def calculator_tool(self, expression):
        try:
            result = eval(expression, {'__builtins__': {}})
            return f"Result: {result}"
        except Exception:
            return "Invalid expression"

    def file_access_tool(self, filename):
        # Dummy file access simulation
        return f"Accessing file {filename}"

    def can_use_tool(self, task, tool_name):
        allowed_tools = self.permission_boundaries.get(task, [])
        return tool_name in allowed_tools

    def perform_task(self, task, tool_name, input_data):
        if not self.can_use_tool(task, tool_name):
            # Log denied attempts
            print(f"Denied tool usage attempt: Tool '{tool_name}' not allowed for task '{task}'")
            return f"Permission denied: Tool '{tool_name}' not allowed for task '{task}'"
        tool_func = self.tools.get(tool_name)
        if not tool_func:
            return f"Tool '{tool_name}' not found"
        return tool_func(input_data)

# Example usage
agent = Agent()

# Allowed usage
output1 = agent.perform_task('data_query', 'search', 'weather today')
output2 = agent.perform_task('math_problem', 'calculator', '2 + 2 * 3')

# Disallowed usage
output3 = agent.perform_task('data_query', 'calculator', '2 + 2')
output4 = agent.perform_task('file_management', 'search', 'file.txt')

print(output1)  # Searching for weather today
print(output2)  # Result: 8
print(output3)  # Permission denied: Tool 'calculator' not allowed for task 'data_query'
print(output4)  # Permission denied: Tool 'search' not allowed for task 'file_management'
Defined permission boundaries mapping tasks to allowed tools.
Added can_use_tool method to check permissions before tool usage.
Modified perform_task to enforce permission checks and deny unauthorized tool usage.
Added logging for denied tool usage attempts.
Results Interpretation

Before: 95% task completion but frequent tool misuse causing errors and risks.
After: 92% task completion with strict permission boundaries, nearly zero misuse errors.

Setting clear permission boundaries helps AI agents use tools safely and appropriately, reducing errors while maintaining strong task performance.
Bonus Experiment
Now try implementing dynamic permission boundaries that adapt based on user roles or context.
💡 Hint
Use additional input parameters like user role or task context to adjust which tools are allowed at runtime.