-
-
Notifications
You must be signed in to change notification settings - Fork 781
Expand file tree
/
Copy pathbasic_thinking.py
More file actions
121 lines (96 loc) · 4.18 KB
/
basic_thinking.py
File metadata and controls
121 lines (96 loc) · 4.18 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3
"""
Basic Thinking Budgets Example for PraisonAI Agents.
This example demonstrates how to use thinking budgets with Agent:
1. Create an Agent with thinking budget
2. Use predefined budget levels
3. Track thinking usage
Usage:
python basic_thinking.py
"""
from praisonaiagents import Agent
from praisonaiagents.thinking import ThinkingBudget, ThinkingTracker
from praisonaiagents.thinking.budget import BudgetLevel
def main():
print("=" * 60)
print("Agent-Centric Thinking Budgets Demo")
print("=" * 60)
# ==========================================================================
# Budget Levels
# ==========================================================================
print("\n--- Available Budget Levels ---")
levels = [
("Minimal", ThinkingBudget.minimal()),
("Low", ThinkingBudget.low()),
("Medium", ThinkingBudget.medium()),
("High", ThinkingBudget.high()),
("Maximum", ThinkingBudget.maximum()),
]
for name, budget in levels:
print(f" {name}: {budget.max_tokens:,} tokens")
# ==========================================================================
# Agent with Thinking Budget
# ==========================================================================
print("\n--- Creating Agent with Thinking Budget ---")
agent = Agent(
name="DeepThinker",
instructions="You are a problem-solving assistant that thinks step by step.",
)
# Set thinking budget via property setter (not constructor param)
agent.thinking_budget = ThinkingBudget.high() # 16,000 tokens for reasoning
print(f"Agent: {agent.name}")
print(f"Thinking budget: {agent.thinking_budget.max_tokens:,} tokens")
print(f"Adaptive: {agent.thinking_budget.adaptive}")
# ==========================================================================
# Custom Budget
# ==========================================================================
print("\n--- Custom Thinking Budget ---")
custom_budget = ThinkingBudget(
max_tokens=12000,
min_tokens=2000,
adaptive=True,
max_time_seconds=120.0
)
agent_custom = Agent(
name="CustomThinker",
instructions="You solve complex problems.",
)
# Set thinking budget via property setter (not constructor param)
agent_custom.thinking_budget = custom_budget
print(f"Agent: {agent_custom.name}")
print(f"Max tokens: {agent_custom.thinking_budget.max_tokens:,}")
print(f"Min tokens: {agent_custom.thinking_budget.min_tokens:,}")
print(f"Time limit: {agent_custom.thinking_budget.max_time_seconds}s")
# ==========================================================================
# Complexity-Based Scaling
# ==========================================================================
print("\n--- Complexity-Based Token Allocation ---")
budget = agent.thinking_budget
complexities = [0.0, 0.25, 0.5, 0.75, 1.0]
for complexity in complexities:
tokens = budget.get_tokens_for_complexity(complexity)
bar = "█" * int(tokens / 1000)
print(f" Complexity {complexity:.2f}: {tokens:,} tokens {bar}")
# ==========================================================================
# Usage Tracking
# ==========================================================================
print("\n--- Session Tracking ---")
tracker = ThinkingTracker()
# Simulate thinking sessions
sessions = [
(8000, 4000, 20.0),
(8000, 6000, 35.0),
(16000, 12000, 60.0),
]
for budget_tokens, tokens_used, time_seconds in sessions:
session = tracker.start_session(budget_tokens=budget_tokens)
tracker.end_session(session, tokens_used=tokens_used, time_seconds=time_seconds)
summary = tracker.get_summary()
print(f" Total sessions: {summary['session_count']}")
print(f" Total tokens used: {summary['total_tokens_used']:,}")
print(f" Average utilization: {summary['average_utilization']:.1%}")
print("\n" + "=" * 60)
print("Demo Complete!")
print("=" * 60)
if __name__ == "__main__":
main()