-
-
Notifications
You must be signed in to change notification settings - Fork 895
Expand file tree
/
Copy path00_agent_fast_context_basic.py
More file actions
73 lines (58 loc) · 2.38 KB
/
00_agent_fast_context_basic.py
File metadata and controls
73 lines (58 loc) · 2.38 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
"""
Fast Context - Basic Example
FastContext provides rapid code search capabilities.
Use it directly from the context module for code search.
FastContext provides:
- 10-20x faster code search than traditional methods
- Parallel execution (8 concurrent searches)
- Automatic caching for repeated queries
Note: FastContext is now accessed via the context module directly,
not as Agent parameters. For context management with agents,
use Agent(context=True) or Agent(context=ManagerConfig(...)).
"""
from praisonaiagents import Agent
from praisonaiagents.context import ManagerConfig
def main():
print("=" * 60)
print("Agent with Context Management - Basic Example")
print("=" * 60)
# Create an agent with context management enabled
# This is the recommended way to use context features
agent = Agent(
name="CodeAssistant",
instructions="You are a helpful code assistant.",
context=True, # Enable context management with defaults
)
print("\n✓ Agent created with context management enabled")
print(f" - context_manager: {agent.context_manager is not None}")
if agent.context_manager:
print(f" - auto_compact: {agent.context_manager.config.auto_compact}")
print(f" - strategy: {agent.context_manager.config.strategy}")
# For FastContext code search, use the module directly
print("\n" + "-" * 60)
print("Using FastContext for code search...")
print("-" * 60)
try:
from praisonaiagents.context.fast import FastContext
fc = FastContext(
workspace_path=".",
model="gpt-4o-mini",
max_turns=4,
max_parallel=8,
)
result = fc.search("class Agent")
print(f"\n✓ Search for 'class Agent':")
print(f" Files found: {result.total_files}")
print(f" Search time: {result.search_time_ms}ms")
if result.total_files > 0:
context = fc.get_context_for_agent("class Agent")
print(f" Context length: {len(context)} characters")
except ImportError:
print("\n⚠ FastContext not available (optional feature)")
except Exception as e:
print(f"\n⚠ FastContext search failed: {e}")
print("\n" + "=" * 60)
print("Context management is now unified via context= param!")
print("=" * 60)
if __name__ == "__main__":
main()