Skip to content

Commit 7f37d75

Browse files
committed
Release v3.11.0
1 parent 26f60fb commit 7f37d75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+10726
-50
lines changed

api.md

Lines changed: 607 additions & 2 deletions
Large diffs are not rendered by default.

docker/Dockerfile.chat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN mkdir -p /root/.praison
1616
# Install Python packages (using latest versions)
1717
RUN pip install --no-cache-dir \
1818
praisonai_tools \
19-
"praisonai>=3.10.27" \
19+
"praisonai>=3.11.0" \
2020
"praisonai[chat]" \
2121
"embedchain[github,youtube]"
2222

docker/Dockerfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RUN mkdir -p /root/.praison
2020
# Install Python packages (using latest versions)
2121
RUN pip install --no-cache-dir \
2222
praisonai_tools \
23-
"praisonai>=3.10.27" \
23+
"praisonai>=3.11.0" \
2424
"praisonai[ui]" \
2525
"praisonai[chat]" \
2626
"praisonai[realtime]" \

docker/Dockerfile.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN mkdir -p /root/.praison
1616
# Install Python packages (using latest versions)
1717
RUN pip install --no-cache-dir \
1818
praisonai_tools \
19-
"praisonai>=3.10.27" \
19+
"praisonai>=3.11.0" \
2020
"praisonai[ui]" \
2121
"praisonai[crewai]"
2222

examples/python/bot_example.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
Messaging Bot Example - Deploy Agents to Telegram, Discord, Slack
3+
4+
This example demonstrates how to configure bots for different
5+
messaging platforms.
6+
"""
7+
8+
import os
9+
from praisonaiagents import Agent, BotConfig
10+
11+
# Telegram Bot Configuration
12+
telegram_config = BotConfig(
13+
token=os.environ.get("TELEGRAM_BOT_TOKEN", ""),
14+
command_prefix="/",
15+
mention_required=True,
16+
typing_indicator=True,
17+
max_message_length=4096,
18+
metadata={"platform": "telegram"}
19+
)
20+
21+
# Discord Bot Configuration
22+
discord_config = BotConfig(
23+
token=os.environ.get("DISCORD_BOT_TOKEN", ""),
24+
command_prefix="!",
25+
mention_required=True,
26+
typing_indicator=True,
27+
metadata={
28+
"platform": "discord",
29+
"guild_ids": [] # Add your guild IDs here
30+
}
31+
)
32+
33+
# Slack Bot Configuration
34+
slack_config = BotConfig(
35+
token=os.environ.get("SLACK_BOT_TOKEN", ""),
36+
command_prefix="/",
37+
mention_required=True,
38+
typing_indicator=True,
39+
metadata={
40+
"platform": "slack",
41+
"app_token": os.environ.get("SLACK_APP_TOKEN", "")
42+
}
43+
)
44+
45+
# Create the agent that will handle messages
46+
assistant = Agent(
47+
name="assistant",
48+
instructions="""You are a helpful assistant that responds to messages
49+
from users on messaging platforms. Be friendly and concise.""",
50+
llm="gpt-4o-mini"
51+
)
52+
53+
if __name__ == "__main__":
54+
print("Bot Configurations:")
55+
print()
56+
57+
print("Telegram Config:")
58+
print(f" Token configured: {bool(telegram_config.token)}")
59+
print(f" Command prefix: {telegram_config.command_prefix}")
60+
print(f" Mention required: {telegram_config.mention_required}")
61+
print()
62+
63+
print("Discord Config:")
64+
print(f" Token configured: {bool(discord_config.token)}")
65+
print(f" Command prefix: {discord_config.command_prefix}")
66+
print()
67+
68+
print("Slack Config:")
69+
print(f" Token configured: {bool(slack_config.token)}")
70+
print(f" Command prefix: {slack_config.command_prefix}")
71+
print()
72+
73+
print("To start a bot, use the CLI:")
74+
print(" praisonai bot telegram --token $TELEGRAM_BOT_TOKEN")
75+
print(" praisonai bot discord --token $DISCORD_BOT_TOKEN")
76+
print(" praisonai bot slack --token $SLACK_BOT_TOKEN")
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
"""
2+
Model Failover Example - Automatic Provider Switching
3+
4+
This example demonstrates how to configure model failover
5+
for reliability and cost optimization.
6+
"""
7+
8+
import os
9+
from praisonaiagents import (
10+
AuthProfile,
11+
FailoverConfig,
12+
FailoverManager,
13+
)
14+
15+
# Create auth profiles for different providers
16+
openai_profile = AuthProfile(
17+
name="openai-primary",
18+
provider="openai",
19+
api_key=os.environ.get("OPENAI_API_KEY", "sk-..."),
20+
priority=1, # Highest priority
21+
rate_limit=100,
22+
)
23+
24+
anthropic_profile = AuthProfile(
25+
name="anthropic-backup",
26+
provider="anthropic",
27+
api_key=os.environ.get("ANTHROPIC_API_KEY", "sk-ant-..."),
28+
priority=2, # Second priority
29+
rate_limit=50,
30+
)
31+
32+
groq_profile = AuthProfile(
33+
name="groq-fallback",
34+
provider="groq",
35+
api_key=os.environ.get("GROQ_API_KEY", "gsk-..."),
36+
priority=3, # Third priority (fast but limited)
37+
rate_limit=30,
38+
)
39+
40+
# Configure failover behavior
41+
failover_config = FailoverConfig(
42+
max_retries=3,
43+
retry_delay=1.0,
44+
exponential_backoff=True,
45+
max_retry_delay=60.0,
46+
failover_on_rate_limit=True,
47+
failover_on_timeout=True,
48+
failover_on_error=True,
49+
)
50+
51+
# Create failover manager
52+
manager = FailoverManager(failover_config)
53+
manager.add_profile(openai_profile)
54+
manager.add_profile(anthropic_profile)
55+
manager.add_profile(groq_profile)
56+
57+
def demonstrate_failover():
58+
"""Demonstrate failover functionality."""
59+
60+
print("Failover Manager Status:")
61+
print()
62+
63+
# Get current status
64+
status = manager.status()
65+
for name, info in status.items():
66+
print(f" {name}:")
67+
print(f" Status: {info.get('status', 'unknown')}")
68+
print(f" Priority: {info.get('priority', 'N/A')}")
69+
print(f" Failures: {info.get('failure_count', 0)}")
70+
print()
71+
72+
# Get next available profile
73+
next_profile = manager.get_next_profile()
74+
if next_profile:
75+
print(f"Next profile to use: {next_profile.name}")
76+
print(f" Provider: {next_profile.provider}")
77+
print(f" Priority: {next_profile.priority}")
78+
print()
79+
80+
# Simulate marking a failure
81+
print("Simulating failure on primary provider...")
82+
manager.mark_failure("openai-primary", "Rate limit exceeded")
83+
84+
# Get next profile after failure
85+
next_profile = manager.get_next_profile()
86+
if next_profile:
87+
print(f"After failure, next profile: {next_profile.name}")
88+
print()
89+
90+
# Get retry delay
91+
delay = manager.get_retry_delay("openai-primary")
92+
print(f"Retry delay for openai-primary: {delay}s")
93+
print()
94+
95+
# Reset all providers
96+
print("Resetting all providers...")
97+
manager.reset_all()
98+
99+
next_profile = manager.get_next_profile()
100+
if next_profile:
101+
print(f"After reset, next profile: {next_profile.name}")
102+
103+
def cost_optimization_example():
104+
"""Example of cost-optimized failover."""
105+
106+
print("\nCost Optimization Example:")
107+
print("-" * 40)
108+
109+
# Create cost-optimized manager
110+
cost_manager = FailoverManager()
111+
112+
# Cheaper model first
113+
cost_manager.add_profile(AuthProfile(
114+
name="gpt-4o-mini",
115+
provider="openai",
116+
api_key=os.environ.get("OPENAI_API_KEY", ""),
117+
priority=1,
118+
metadata={"model": "gpt-4o-mini", "cost_per_1k": 0.00015}
119+
))
120+
121+
# Premium model as fallback
122+
cost_manager.add_profile(AuthProfile(
123+
name="gpt-4o",
124+
provider="openai",
125+
api_key=os.environ.get("OPENAI_API_KEY", ""),
126+
priority=2,
127+
metadata={"model": "gpt-4o", "cost_per_1k": 0.005}
128+
))
129+
130+
# Most expensive as last resort
131+
cost_manager.add_profile(AuthProfile(
132+
name="claude-opus",
133+
provider="anthropic",
134+
api_key=os.environ.get("ANTHROPIC_API_KEY", ""),
135+
priority=3,
136+
metadata={"model": "claude-3-opus", "cost_per_1k": 0.015}
137+
))
138+
139+
print("Cost-optimized failover chain:")
140+
for profile in [
141+
cost_manager.get_profile("gpt-4o-mini"),
142+
cost_manager.get_profile("gpt-4o"),
143+
cost_manager.get_profile("claude-opus"),
144+
]:
145+
if profile:
146+
cost = profile.metadata.get("cost_per_1k", "N/A")
147+
print(f" {profile.priority}. {profile.name} (${cost}/1K tokens)")
148+
149+
if __name__ == "__main__":
150+
print("Model Failover Configuration")
151+
print("=" * 40)
152+
print()
153+
154+
print("Failover Config:")
155+
print(f" Max retries: {failover_config.max_retries}")
156+
print(f" Initial delay: {failover_config.retry_delay}s")
157+
print(f" Exponential backoff: {failover_config.exponential_backoff}")
158+
print(f" Max delay: {failover_config.max_retry_delay}s")
159+
print()
160+
161+
print("Auth Profiles:")
162+
for profile in [openai_profile, anthropic_profile, groq_profile]:
163+
print(f" {profile.name}:")
164+
print(f" Provider: {profile.provider}")
165+
print(f" Priority: {profile.priority}")
166+
print(f" Rate limit: {profile.rate_limit} req/min")
167+
print()
168+
169+
demonstrate_failover()
170+
cost_optimization_example()

examples/python/gateway_example.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Gateway Example - Multi-Agent Coordination
3+
4+
This example demonstrates how to use the Gateway for coordinating
5+
multiple agents and managing real-time communication.
6+
"""
7+
8+
from praisonaiagents import Agent, GatewayConfig, SessionConfig
9+
10+
# Configure the gateway
11+
gateway_config = GatewayConfig(
12+
host="127.0.0.1",
13+
port=8765,
14+
max_connections=100,
15+
heartbeat_interval=30,
16+
session_config=SessionConfig(
17+
timeout=3600, # 1 hour session timeout
18+
max_messages=500,
19+
)
20+
)
21+
22+
# Create specialized agents
23+
researcher = Agent(
24+
name="researcher",
25+
instructions="You research topics thoroughly and provide detailed information.",
26+
llm="gpt-4o-mini"
27+
)
28+
29+
writer = Agent(
30+
name="writer",
31+
instructions="You write clear, engaging content based on research.",
32+
llm="gpt-4o-mini"
33+
)
34+
35+
# Example: Simple agent interaction
36+
if __name__ == "__main__":
37+
print("Gateway Configuration:")
38+
print(f" Host: {gateway_config.host}")
39+
print(f" Port: {gateway_config.port}")
40+
print(f" WebSocket URL: {gateway_config.ws_url}")
41+
print(f" Max Connections: {gateway_config.max_connections}")
42+
print()
43+
44+
# Test agent
45+
response = researcher.start("What are the key benefits of multi-agent systems?")
46+
print("Researcher Response:")
47+
print(response)

0 commit comments

Comments
 (0)