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

1from signalwire import AgentBase
2from signalwire import FunctionResult
3
4agent = AgentBase(name="my-agent", route="/agent")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="verify_identity", description="Verify caller identity")
8def verify_identity(args, raw_data):
9 ssn = args.get("ssn")
10 # ... verify SSN ...
11 return (
12 FunctionResult("I've verified your identity.")
13 .replace_in_history(True)
14 )
15
16agent.serve()

Replace with Summary

1from signalwire import AgentBase
2from signalwire import FunctionResult
3
4agent = AgentBase(name="my-agent", route="/agent")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="process_payment", description="Process a payment")
8def process_payment(args, raw_data):
9 card_number = args.get("card_number")
10 # ... process payment ...
11 return (
12 FunctionResult("Payment processed successfully.")
13 .replace_in_history("Payment information was collected and processed.")
14 )
15
16agent.serve()