You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
expires_in=expires_in_hours(12), # optional — default is 24 h (Agora max)
44
+
)
45
+
46
+
# start() returns a session ID unique to this agent session
47
+
agent_session_id = session.start()
48
+
49
+
# In production, stop is typically called when your client signals the session has ended.
50
+
# Your server receives that request and calls session.stop().
51
+
session.stop()
52
+
```
53
+
54
+
For async usage, use `AsyncAgora` and `await session.start()`, etc. See [Quick Start](docs/getting-started/quick-start.md).
55
+
56
+
### Session lifecycle
57
+
58
+
`start()` joins the agent to the channel and returns a **session ID** — a unique identifier for this agent session. The session stays active until `stop()` is called.
59
+
60
+
There are two ways to stop a session depending on how your server is structured:
61
+
62
+
**Option 1 — Hold the session in memory:**
63
+
64
+
```python
65
+
# start-session handler
66
+
agent_session_id = session.start() # unique ID for this session
67
+
# stop-session handler (same process, session still in scope)
39
68
session.stop()
40
69
```
41
70
42
-
For async usage, use `AsyncAgora` and `await session.start()`, `await session.say()`, etc. See [Quick Start](docs/getting-started/quick-start.md).
71
+
**Option 2 — Store the session ID and stop by ID (stateless servers):**
72
+
73
+
```python
74
+
# start-session handler: return session ID to your client app
75
+
agent_session_id = session.start()
76
+
# ... return agent_session_id to client ...
77
+
78
+
# stop-session handler: client sends back agent_session_id
Copy file name to clipboardExpand all lines: docs/getting-started/authentication.md
+48-5Lines changed: 48 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,11 +68,35 @@ client = AsyncAgora(
68
68
)
69
69
```
70
70
71
+
## Pre-built token
72
+
73
+
Pass a manually generated `agora token=...` string via `auth_token`. Use this for debugging or when you want to control the REST API token lifecycle yourself:
74
+
75
+
```python
76
+
from agora_agent import Agora, Area
77
+
from agora_agent.agentkit.token import generate_convo_ai_token
|`channel_name`|`str`| Yes | — | Channel the agent will join |
123
147
|`account`|`str`| Yes | — | Agent UID as a string (e.g. `"1001"`) |
124
-
|`token_expire`|`int`| No |`3600`| Seconds until token expires |
148
+
|`token_expire`|`int`| No |`86400`| Seconds until token expires (max: 86400 = 24 h)|
125
149
|`privilege_expire`|`int`| No |`0`| Seconds until privileges expire (0 = same as `token_expire`) |
126
150
151
+
## Token expiry
152
+
153
+
When the SDK auto-generates a token (app credentials mode, or session without a pre-built `token`), the default lifetime is **86400 seconds (24 hours)** — the Agora maximum. You can customise this via `expires_in` on `create_session()`:
154
+
155
+
```python
156
+
from agora_agent.agentkit import expires_in_hours, expires_in_minutes
`expires_in_hours()` and `expires_in_minutes()` validate the value and raise `ValueError` if it is ≤ 0, or warn and cap at 86400 if it exceeds 24 hours. Valid range: **1–86400 seconds**.
169
+
127
170
## Areas
128
171
129
172
The `area` parameter determines which Agora region your requests are routed to:
Copy file name to clipboardExpand all lines: docs/reference/agent.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,6 +115,7 @@ create_session(
115
115
token: Optional[str] =None,
116
116
idle_timeout: Optional[int] =None,
117
117
enable_string_uid: Optional[bool] =None,
118
+
expires_in: Optional[int] =None,
118
119
) -> AgentSession
119
120
```
120
121
@@ -127,7 +128,8 @@ Creates an `AgentSession` bound to the given client and channel.
127
128
|`agent_uid`|`str`| Yes | UID for the agent |
128
129
|`remote_uids`|`List[str]`| Yes | UIDs of remote participants |
129
130
|`name`|`Optional[str]`| No | Session name (defaults to agent name) |
130
-
|`token`|`Optional[str]`| No | Pre-built RTC token |
131
+
|`token`|`Optional[str]`| No | Pre-built RTC+RTM token |
132
+
|`expires_in`|`Optional[int]`| No | Token lifetime in seconds (default: `86400` = 24 h, Agora max). Only applies when the token is auto-generated. Use `expires_in_hours()` or `expires_in_minutes()` for clarity. Valid range: 1–86400. |
131
133
|`idle_timeout`|`Optional[int]`| No | Idle timeout in seconds |
132
134
|`enable_string_uid`|`Optional[bool]`| No | Enable string UIDs |
0 commit comments