def add_to_history(tool_context: ToolContext, event: str) -> Dict[str, Any]: history = tool_context.state.get("history", []) history.append({ "event": event, "timestamp": datetime.now().isoformat(), "session_id": tool_context.session_id }) # Keep only last 50 events tool_context.state["history"] = history[-50:] return {"status": "success", "history_length": len(history)} __ __