update_global_data

View as MarkdownOpen in Claude

Set or update key-value pairs in the global session data. Global data persists for the entire agent session and is accessible in prompt variable expansion (${global_data.key}) and by all SWAIG functions.

Parameters

data
dict[str, Any]Required

Dictionary of key-value pairs to merge into the global data store. Existing keys are overwritten; new keys are added.

Returns

FunctionResult — self, for chaining.

Example

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="save_customer_info", description="Save customer information")
def save_customer_info(args, raw_data):
return (
FunctionResult(f"I've noted your information, {args.get('name')}.")
.update_global_data({
"customer_id": args.get("customer_id"),
"customer_name": args.get("name"),
"verified": True
})
)
agent.serve()