replace_in_history

View as MarkdownOpen in Claude

Control how this function call appears in the AI’s conversation history. Use this to remove sensitive information (credit card numbers, SSNs) or replace verbose tool results with concise summaries.

When True is passed, the entire tool-call/result pair is removed from history. When a string is passed, the pair is replaced with that text as an assistant message.

Parameters

text
str | boolDefaults to True
  • True — remove the tool-call and result pair from history entirely
  • A str — replace the pair with an assistant message containing this text

Returns

FunctionResult — self, for chaining.

Examples

Remove Sensitive Exchange

from signalwire import AgentBase
from signalwire import FunctionResult
agent = AgentBase(name="my-agent", route="/agent")
agent.set_prompt_text("You are a helpful assistant.")
@agent.tool(name="verify_identity", description="Verify caller identity")
def verify_identity(args, raw_data):
ssn = args.get("ssn")
# ... verify SSN ...
return (
FunctionResult("I've verified your identity.")
.replace_in_history(True)
)
agent.serve()

Replace with Summary

from signalwire import AgentBase
from signalwire import FunctionResult
agent = AgentBase(name="my-agent", route="/agent")
agent.set_prompt_text("You are a helpful assistant.")
@agent.tool(name="process_payment", description="Process a payment")
def process_payment(args, raw_data):
card_number = args.get("card_number")
# ... process payment ...
return (
FunctionResult("Payment processed successfully.")
.replace_in_history("Payment information was collected and processed.")
)
agent.serve()