FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-agents-examples/basics/context_variables.py at main · cdevry/python-agents-examples · GitHub
cdevry
/
python-agents-examples
Public
forked from
livekit-examples/python-agents-examples
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-agents-examples
/
basics
/
context_variables.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (40 loc) · 1.38 KB
Breadcrumbs
python-agents-examples
/
basics
/
context_variables.py
Copy path
File metadata and controls
51 lines (40 loc) · 1.38 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import
logging
from
pathlib
import
Path
from
dotenv
import
load_dotenv
from
livekit
.
agents
import
JobContext
,
WorkerOptions
,
cli
from
livekit
.
agents
.
voice
import
Agent
,
AgentSession
from
livekit
.
plugins
import
openai
,
deepgram
,
silero
load_dotenv
(
dotenv_path
=
Path
(
__file__
).
parent
.
parent
/
'.env'
)
logger
=
logging
.
getLogger
(
"context-variables"
)
logger
.
setLevel
(
logging
.
INFO
)
class
ContextAgent
(
Agent
):
def
__init__
(
self
,
context_vars
=
None
)
->
None
:
instructions
=
"""
You are a helpful agent. The user's name is {name}.
They are {age} years old and live in {city}.
"""
if
context_vars
:
instructions
=
instructions
.
format
(
**
context_vars
)
super
().
__init__
(
instructions
=
instructions
,
stt
=
deepgram
.
STT
(),
llm
=
openai
.
LLM
(
model
=
"gpt-4o"
),
tts
=
openai
.
TTS
(),
vad
=
silero
.
VAD
.
load
()
)
async
def
on_enter
(
self
):
self
.
session
.
generate_reply
()
async
def
entrypoint
(
ctx
:
JobContext
):
await
ctx
.
connect
()
context_variables
=
{
"name"
:
"Shayne"
,
"age"
:
35
,
"city"
:
"Toronto"
}
session
=
AgentSession
()
await
session
.
start
(
agent
=
ContextAgent
(
context_vars
=
context_variables
),
room
=
ctx
.
room
)
if
__name__
==
"__main__"
:
cli
.
run_app
(
WorkerOptions
(
entrypoint_fnc
=
entrypoint
))
Back
|
FazBrowse Home
|
New Git URL