Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/python/managed-agents/provider/all_providers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""All compute providers — comprehensive test across Local, Docker, E2B, and Modal.

This example mirrors the Anthropic app.py but uses the local provider with
various compute backends instead of Anthropic's managed infrastructure.
This example demonstrates local agent loops with various compute backends for tool sandboxing.
Uses the new LocalAgent class to clearly indicate local execution with optional cloud compute.

Requires:
- Docker running locally
- E2B_API_KEY set
- modal CLI configured (modal token set)
"""
import asyncio
from praisonai import Agent, ManagedAgent, LocalManagedConfig
from praisonai import Agent
from praisonai.integrations import LocalAgent, LocalAgentConfig


async def test_provider(name, compute, extra_provision_kwargs=None):
Expand All @@ -18,10 +19,9 @@ async def test_provider(name, compute, extra_provision_kwargs=None):
print(f" PROVIDER: {name}")
print(f"{'='*60}")

managed = ManagedAgent(
provider="local",
managed = LocalAgent(
compute=compute,
config=LocalManagedConfig(
config=LocalAgentConfig(
model="gpt-4o-mini",
system="You are a helpful assistant. Be concise.",
name=f"{name}Agent",
Expand Down
13 changes: 7 additions & 6 deletions examples/python/managed-agents/provider/local_basic.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Local provider — basic managed agent with gpt-4o-mini.
"""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, ManagedAgent, LocalManagedConfig
from praisonai import Agent
from praisonai.integrations import LocalAgent, LocalAgentConfig

# Create a local managed agent (auto-detects local when no ANTHROPIC_API_KEY)
managed = ManagedAgent(
provider="local",
config=LocalManagedConfig(
# 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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Anthropic hosted runtime — entire agent runs on Anthropic's managed infrastructure.

Uses the new canonical HostedAgent class which clearly communicates that the entire
agent loop runs in Anthropic's cloud, not locally.
"""
from praisonai import Agent
from praisonai.integrations import HostedAgent, HostedAgentConfig

# Create a hosted agent running entirely on Anthropic's managed runtime
hosted = HostedAgent(
provider="anthropic",
config=HostedAgentConfig(
model="claude-3-5-sonnet-latest",
system="You are a helpful coding assistant. Be concise.",
name="AnthropicHostedAgent",
tools=[{"type": "agent_toolset_20260401"}],
),
)

agent = Agent(name="anthropic-hosted", backend=hosted)

# 1. Basic execution - runs entirely in Anthropic's cloud
print("[1] Hosted execution on Anthropic infrastructure...")
result = agent.start("What is the capital of France? One word.", stream=True)
print(f" Result: {result}")

# 2. Agent metadata from Anthropic's API
print(f"\n[2] Agent ID: {hosted.agent_id}")
print(f" Version: {hosted.agent_version}")
print(f" Env ID: {hosted.environment_id}")
print(f" Session: {hosted.session_id}")

# 3. Multi-turn (same session keeps context in Anthropic's cloud)
print("\n[3] Multi-turn conversation...")
result = agent.start("What country is that city in?", stream=True)
print(f" Result: {result}")

# 4. Usage tracking from Anthropic's usage API
info = hosted.retrieve_session()
print(f"\n[4] Usage: in={info['usage']['input_tokens']}, out={info['usage']['output_tokens']}")

# 5. List all sessions for this agent
sessions = hosted.list_sessions()
print(f"\n[5] Sessions: {len(sessions)}")
for s in sessions[:3]: # Show first 3
print(f" {s['id']} | {s['status']}")

print("\nDone! Agent loop ran entirely on Anthropic's managed infrastructure.")
46 changes: 46 additions & 0 deletions examples/python/managed-agents/provider/runtime_local_gemini.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Local agent loop with Gemini LLM — runs locally, not in a managed runtime.

Uses the new canonical LocalAgent class which clearly communicates that only the
agent loop runs locally. The LLM calls go to Google's Gemini API, but there's no managed runtime involved.
"""
from praisonai import Agent
from praisonai.integrations import LocalAgent, LocalAgentConfig

# Create a local agent using Gemini LLM
local = LocalAgent(
config=LocalAgentConfig(
model="gemini/gemini-2.0-flash", # Use Gemini with litellm routing prefix
system="You are a helpful coding assistant. Be concise.",
name="LocalGeminiAgent",
tools=["execute_command", "read_file", "write_file"],
),
)

agent = Agent(name="local-gemini", backend=local)

# 1. Basic execution - agent loop runs locally, LLM calls go to Gemini
print("[1] Local execution with Gemini LLM...")
result = agent.start("What is the capital of France? One word.", stream=True)
print(f" Result: {result}")

# 2. Agent metadata (locally generated UUIDs)
print(f"\n[2] Agent ID: {local.agent_id}")
print(f" Version: {local.agent_version}")
print(f" Env ID: {local.environment_id}")
print(f" Session: {local.session_id}")

# 3. Multi-turn conversation (session state maintained locally)
print("\n[3] Multi-turn conversation...")
result = agent.start("What country is that city in?", stream=True)
print(f" Result: {result}")

# 4. Usage tracking (accumulated locally)
info = local.retrieve_session()
print(f"\n[4] Usage: in={info['usage']['input_tokens']}, out={info['usage']['output_tokens']}")

# 5. Tool execution (runs in local subprocess)
print("\n[5] Tool execution example...")
result = agent.start("Create a file called hello_gemini.txt with 'Hello from Gemini agent!'", stream=True)
print(f" Tool result: {result}")

print("\nDone! Agent loop ran locally with Gemini LLM calls.")
46 changes: 46 additions & 0 deletions examples/python/managed-agents/provider/runtime_local_ollama.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Local agent loop with Ollama LLM — runs locally, not in a managed runtime.

Uses the new canonical LocalAgent class which clearly communicates that only the
agent loop runs locally. The LLM calls go to a local Ollama instance, no managed runtime involved.
"""
from praisonai import Agent
from praisonai.integrations import LocalAgent, LocalAgentConfig

# Create a local agent using Ollama LLM
local = LocalAgent(
config=LocalAgentConfig(
model="ollama/llama3.2", # Use Ollama with litellm routing prefix
system="You are a helpful coding assistant. Be concise.",
name="LocalOllamaAgent",
tools=["execute_command", "read_file", "write_file"],
),
)

agent = Agent(name="local-ollama", backend=local)

# 1. Basic execution - agent loop runs locally, LLM calls go to local Ollama
print("[1] Local execution with Ollama LLM...")
result = agent.start("What is the capital of France? One word.", stream=True)
print(f" Result: {result}")

# 2. Agent metadata (locally generated UUIDs)
print(f"\n[2] Agent ID: {local.agent_id}")
print(f" Version: {local.agent_version}")
print(f" Env ID: {local.environment_id}")
print(f" Session: {local.session_id}")

# 3. Multi-turn conversation (session state maintained locally)
print("\n[3] Multi-turn conversation...")
result = agent.start("What country is that city in?", stream=True)
print(f" Result: {result}")

# 4. Usage tracking (accumulated locally)
info = local.retrieve_session()
print(f"\n[4] Usage: in={info['usage']['input_tokens']}, out={info['usage']['output_tokens']}")

# 5. Tool execution (runs in local subprocess)
print("\n[5] Tool execution example...")
result = agent.start("Create a file called hello_ollama.txt with 'Hello from Ollama agent!'", stream=True)
print(f" Tool result: {result}")

print("\nDone! Agent loop ran locally with Ollama LLM calls.")
46 changes: 46 additions & 0 deletions examples/python/managed-agents/provider/runtime_local_openai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Local agent loop with OpenAI LLM — runs locally, not in a managed runtime.

Uses the new canonical LocalAgent class which clearly communicates that only the
agent loop runs locally. The LLM calls go to OpenAI, but there's no managed runtime involved.
"""
from praisonai import Agent
from praisonai.integrations import LocalAgent, LocalAgentConfig

# Create a local agent using OpenAI's LLM
local = LocalAgent(
config=LocalAgentConfig(
model="gpt-4o-mini",
system="You are a helpful coding assistant. Be concise.",
name="LocalOpenAIAgent",
tools=["execute_command", "read_file", "write_file"],
),
)

agent = Agent(name="local-openai", backend=local)

# 1. Basic execution - agent loop runs locally, LLM calls go to OpenAI
print("[1] Local execution with OpenAI LLM...")
result = agent.start("What is the capital of France? One word.", stream=True)
print(f" Result: {result}")

# 2. Agent metadata (locally generated UUIDs)
print(f"\n[2] Agent ID: {local.agent_id}")
print(f" Version: {local.agent_version}")
print(f" Env ID: {local.environment_id}")
print(f" Session: {local.session_id}")

# 3. Multi-turn conversation (session state maintained locally)
print("\n[3] Multi-turn conversation...")
result = agent.start("What country is that city in?", stream=True)
print(f" Result: {result}")

# 4. Usage tracking (accumulated locally)
info = local.retrieve_session()
print(f"\n[4] Usage: in={info['usage']['input_tokens']}, out={info['usage']['output_tokens']}")

# 5. Tool execution (runs in local subprocess)
print("\n[5] Tool execution example...")
result = agent.start("Create a file called hello.txt with 'Hello from local agent!'", stream=True)
print(f" Tool result: {result}")

print("\nDone! Agent loop ran locally with OpenAI LLM calls.")
18 changes: 18 additions & 0 deletions src/praisonai/praisonai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
'LocalManagedConfig', # backward compat alias
'SandboxedAgent', # new honest name
'SandboxedAgentConfig', # new honest name
# New canonical agent backends
'HostedAgent',
'HostedAgentConfig',
'LocalAgent',
'LocalAgentConfig',
]

# Telemetry initialization state
Expand Down Expand Up @@ -123,6 +128,19 @@ def __getattr__(name):
elif name in ('ManagedConfig', 'ManagedBackendConfig'):
from .integrations.managed_agents import ManagedConfig
return ManagedConfig
# New canonical agent backends
elif name == 'HostedAgent':
from .integrations.hosted_agent import HostedAgent
return HostedAgent
elif name == 'HostedAgentConfig':
from .integrations.hosted_agent import HostedAgentConfig
return HostedAgentConfig
elif name == 'LocalAgent':
from .integrations.local_agent import LocalAgent
return LocalAgent
elif name == 'LocalAgentConfig':
from .integrations.local_agent import LocalAgentConfig
return LocalAgentConfig
elif name in ('DB', 'PraisonAIDB', 'PraisonDB'):
from .db.adapter import DB
return DB
Expand Down
18 changes: 18 additions & 0 deletions src/praisonai/praisonai/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
'SandboxedAgentConfig', # new honest name
'ManagedAgentIntegration', # backward compat alias
'ManagedBackendConfig', # backward compat alias
# New canonical agent backends
'HostedAgent',
'HostedAgentConfig',
'LocalAgent',
'LocalAgentConfig',
'get_available_integrations',
'ExternalAgentRegistry',
'get_registry',
Expand Down Expand Up @@ -107,4 +112,17 @@ def __getattr__(name):
elif name == 'create_integration':
from .registry import create_integration
return create_integration
# New canonical agent backends
elif name == 'HostedAgent':
from .hosted_agent import HostedAgent
return HostedAgent
elif name == 'HostedAgentConfig':
from .hosted_agent import HostedAgentConfig
return HostedAgentConfig
elif name == 'LocalAgent':
from .local_agent import LocalAgent
return LocalAgent
elif name == 'LocalAgentConfig':
from .local_agent import LocalAgentConfig
return LocalAgentConfig
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
Loading