-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathlocal_basic.py
More file actions
46 lines (37 loc) · 1.4 KB
/
local_basic.py
File metadata and controls
46 lines (37 loc) · 1.4 KB
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
"""Local agent — basic local execution with gpt-4o-mini.
No external infrastructure needed. Runs the agent loop locally.
Uses the new canonical LocalAgent class for clarity.
"""
from praisonai import Agent
from praisonai.integrations import LocalAgent, LocalAgentConfig
# Create a local agent (runs locally, no managed runtime)
managed = LocalAgent(
config=LocalAgentConfig(
model="gpt-4o-mini",
system="You are a helpful assistant. Be concise.",
name="LocalAgent",
),
)
agent = Agent(name="local-basic", backend=managed)
# 1. Basic execution
print("[1] Basic execution...")
result = agent.start("What is the capital of France? One word.", stream=True)
print(f" Result: {result}")
# 2. Agent metadata
print(f"\n[2] Agent ID: {managed.agent_id}")
print(f" Version: {managed.agent_version}")
print(f" Env ID: {managed.environment_id}")
print(f" Session: {managed.session_id}")
# 3. Multi-turn (same session keeps context)
print("\n[3] Multi-turn...")
result = agent.start("What country is that city in?", stream=True)
print(f" Result: {result}")
# 4. Usage tracking
info = managed.retrieve_session()
print(f"\n[4] Usage: in={info['usage']['input_tokens']}, out={info['usage']['output_tokens']}")
# 5. List sessions
sessions = managed.list_sessions()
print(f"\n[5] Sessions: {len(sessions)}")
for s in sessions:
print(f" {s['id']} | {s['status']}")
print("\nDone!")