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

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="save_customer_info", description="Save customer information")
8def save_customer_info(args, raw_data):
9 return (
10 FunctionResult(f"I've noted your information, {args.get('name')}.")
11 .update_global_data({
12 "customer_id": args.get("customer_id"),
13 "customer_name": args.get("name"),
14 "verified": True
15 })
16 )
17
18agent.serve()