1+ """
2+ MaximWrappedAgentSession - A wrapper around LiveKit's AgentSession with additional parameters.
3+
4+ This module provides a MaximWrappedAgentSession class that extends the original AgentSession
5+ with the ability to accept additional parameters for Maxim integration. This is useful for
6+ passing custom metadata (like session names and tags) that can be accessed during session
7+ instrumentation.
8+
9+ Usage:
10+ from maxim.logger.livekit import MaximWrappedAgentSession
11+
12+ # Instead of:
13+ # session = AgentSession(turn_detection="manual")
14+
15+ # Use:
16+ session = MaximWrappedAgentSession(
17+ turn_detection="manual",
18+ maxim_params={
19+ "session_name": "my-custom-session",
20+ "tags": {"user_id": "123", "department": "sales"}
21+ }
22+ )
23+ """
24+
25+ from typing import Any , Dict , Optional , TypedDict
26+ from livekit .agents import AgentSession
27+
28+
29+ class MaximParams (TypedDict , total = False ):
30+ """Type definition for Maxim parameters.
31+
32+ Attributes:
33+ session_name: Optional custom name for the session
34+ tags: Optional dictionary of key-value tags to attach to the session
35+ """
36+ session_name : str
37+ tags : Dict [str , Any ]
38+
39+
40+ class MaximWrappedAgentSession (AgentSession ):
41+ """
42+ A wrapper around LiveKit's AgentSession that accepts additional parameters.
43+
44+ This class extends AgentSession to allow passing custom parameters for Maxim
45+ integration that can be accessed during session instrumentation, particularly
46+ in the intercept_session_start function.
47+
48+ Args:
49+ *args: Positional arguments passed to the original AgentSession
50+ maxim_params: Optional MaximParams with session_name and tags
51+ **kwargs: Keyword arguments passed to the original AgentSession
52+
53+ Example:
54+ session = MaximWrappedAgentSession(
55+ turn_detection="manual",
56+ maxim_params={
57+ "session_name": "customer-support-session",
58+ "tags": {"user_id": "user_123", "department": "sales"}
59+ }
60+ )
61+ """
62+
63+ def __init__ (self , * args , maxim_params : Optional [MaximParams ] = None , ** kwargs ):
64+ """
65+ Initialize the MaximWrappedAgentSession.
66+
67+ Args:
68+ *args: Positional arguments for AgentSession
69+ maxim_params: MaximParams with optional session_name and tags
70+ **kwargs: Keyword arguments for AgentSession
71+ """
72+ # Initialize the parent AgentSession with original parameters
73+ super ().__init__ (* args , ** kwargs )
74+
75+ # Store the additional parameters
76+ self ._maxim_params : MaximParams = maxim_params or {}
77+
78+ def get_maxim_param (self , key : str , default : Any = None ) -> Any :
79+ """
80+ Get a specific Maxim parameter value.
81+
82+ Args:
83+ key: The parameter key to retrieve
84+ default: Default value if key is not found
85+
86+ Returns:
87+ The parameter value or default if not found
88+ """
89+ return self ._maxim_params .get (key , default )
90+
91+ def get_all_maxim_params (self ) -> MaximParams :
92+ """
93+ Get all Maxim parameters.
94+
95+ Returns:
96+ Copy of all custom parameters
97+ """
98+ return self ._maxim_params .copy ()
99+
0 commit comments