Skip to main content

Removing Tools from Agent

By Name (String)

agent.remove_tools("add")
agent.remove_tools(["add", "multiply"])

By Object Reference

agent.remove_tools(multiply)
agent.remove_tools([add, multiply])

Mixed (Name + Object)

agent.remove_tools([add, "multiply"])
agent.remove_tools(["add", multiply])

Complete Agent Example

from upsonic import Agent, Task
from upsonic.tools import tool

@tool
def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b

@tool
def multiply(a: int, b: int) -> int:
    """Multiply two numbers."""
    return a * b

agent = Agent("anthropic/claude-sonnet-4-5", tools=[add, multiply])

# Use both tools
task1 = Task(description="What is 5 + 3?")
result = agent.print_do(task1)
print("Result:", result)

# Remove add, keep multiply
agent.remove_tools("add")

# Now only multiply is available
task2 = Task(description="What is 6 * 7?")
result = agent.print_do(task2)
print("Result:", result)

Removing Tools from Task

Removing tools from tasks requires the agent reference:
from upsonic import Agent, Task
from upsonic.tools import tool

@tool
def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b

@tool
def multiply(a: int, b: int) -> int:
    """Multiply two numbers."""
    return a * b

agent = Agent("anthropic/claude-sonnet-4-5")
task = Task(description="Calculate 5 + 3", tools=[add, multiply])

# Remove from task (requires agent reference)
task.remove_tools("multiply", agent)

result = agent.print_do(task)
print("Result:", result)

Task Removal Methods

task.remove_tools("add", agent)                  # By name
task.remove_tools(multiply, agent)               # By object
task.remove_tools([add, "multiply"], agent)       # Mixed

Key Points

  • Remove by name: Works for all tool types
  • Remove by object: Removes entire container (ToolKit/Class/MCP/Agent) or single function
  • Mixed removal: Combine names and objects in one call
  • Agent tools: Removed from all future tasks
  • Task tools: Requires agent reference for removal