praisonaiagents 0.0.80__py3-none-any.whl → 0.0.81__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,9 +23,9 @@ import uuid
23
23
  from dataclasses import dataclass
24
24
 
25
25
  # Global variables for API server
26
- _server_started = False
27
- _registered_agents = {}
28
- _shared_app = None
26
+ _server_started = {} # Dict of port -> started boolean
27
+ _registered_agents = {} # Dict of port -> Dict of path -> agent_id
28
+ _shared_apps = {} # Dict of port -> FastAPI app
29
29
 
30
30
  # Don't import FastAPI dependencies here - use lazy loading instead
31
31
 
@@ -1421,7 +1421,7 @@ Your Goal: {self.goal}
1421
1421
  Returns:
1422
1422
  None
1423
1423
  """
1424
- global _server_started, _registered_agents, _shared_app
1424
+ global _server_started, _registered_agents, _shared_apps
1425
1425
 
1426
1426
  # Try to import FastAPI dependencies - lazy loading
1427
1427
  try:
@@ -1447,32 +1447,41 @@ Your Goal: {self.goal}
1447
1447
  print("pip install 'praisonaiagents[api]'")
1448
1448
  return None
1449
1449
 
1450
- # Initialize shared FastAPI app if not already created
1451
- if _shared_app is None:
1452
- _shared_app = FastAPI(
1453
- title="PraisonAI Agents API",
1450
+ # Initialize port-specific collections if needed
1451
+ if port not in _registered_agents:
1452
+ _registered_agents[port] = {}
1453
+
1454
+ # Initialize shared FastAPI app if not already created for this port
1455
+ if _shared_apps.get(port) is None:
1456
+ _shared_apps[port] = FastAPI(
1457
+ title=f"PraisonAI Agents API (Port {port})",
1454
1458
  description="API for interacting with PraisonAI Agents"
1455
1459
  )
1456
1460
 
1457
1461
  # Add a root endpoint with a welcome message
1458
- @_shared_app.get("/")
1462
+ @_shared_apps[port].get("/")
1459
1463
  async def root():
1460
- return {"message": "Welcome to PraisonAI Agents API. See /docs for usage."}
1464
+ return {
1465
+ "message": f"Welcome to PraisonAI Agents API on port {port}. See /docs for usage.",
1466
+ "endpoints": list(_registered_agents[port].keys())
1467
+ }
1461
1468
 
1462
1469
  # Add healthcheck endpoint
1463
- @_shared_app.get("/health")
1470
+ @_shared_apps[port].get("/health")
1464
1471
  async def healthcheck():
1465
- return {"status": "ok", "agents": list(_registered_agents.keys())}
1472
+ return {
1473
+ "status": "ok",
1474
+ "endpoints": list(_registered_agents[port].keys())
1475
+ }
1466
1476
 
1467
1477
  # Normalize path to ensure it starts with /
1468
1478
  if not path.startswith('/'):
1469
1479
  path = f'/{path}'
1470
1480
 
1471
- # Check if path is already registered by another agent
1472
- if path in _registered_agents and _registered_agents[path] != self.agent_id:
1473
- existing_agent = _registered_agents[path]
1474
- logging.warning(f"Path '{path}' is already registered by another agent. Please use a different path.")
1475
- print(f"⚠️ Warning: Path '{path}' is already registered by another agent.")
1481
+ # Check if path is already registered for this port
1482
+ if path in _registered_agents[port]:
1483
+ logging.warning(f"Path '{path}' is already registered on port {port}. Please use a different path.")
1484
+ print(f"⚠️ Warning: Path '{path}' is already registered on port {port}.")
1476
1485
  # Use a modified path to avoid conflicts
1477
1486
  original_path = path
1478
1487
  path = f"{path}_{self.agent_id[:6]}"
@@ -1480,10 +1489,10 @@ Your Goal: {self.goal}
1480
1489
  print(f"🔄 Using '{path}' instead")
1481
1490
 
1482
1491
  # Register the agent to this path
1483
- _registered_agents[path] = self.agent_id
1492
+ _registered_agents[port][path] = self.agent_id
1484
1493
 
1485
1494
  # Define the endpoint handler
1486
- @_shared_app.post(path)
1495
+ @_shared_apps[port].post(path)
1487
1496
  async def handle_agent_query(request: Request, query_data: Optional[AgentQuery] = None):
1488
1497
  # Handle both direct JSON with query field and form data
1489
1498
  if query_data is None:
@@ -1521,17 +1530,18 @@ Your Goal: {self.goal}
1521
1530
 
1522
1531
  print(f"🚀 Agent '{self.name}' available at http://{host}:{port}{path}")
1523
1532
 
1524
- # Start the server if it's not already running
1525
- if not _server_started:
1526
- _server_started = True
1533
+ # Start the server if it's not already running for this port
1534
+ if not _server_started.get(port, False):
1535
+ # Mark the server as started first to prevent duplicate starts
1536
+ _server_started[port] = True
1527
1537
 
1528
1538
  # Start the server in a separate thread
1529
1539
  def run_server():
1530
1540
  try:
1531
1541
  print(f"✅ FastAPI server started at http://{host}:{port}")
1532
1542
  print(f"📚 API documentation available at http://{host}:{port}/docs")
1533
- print(f"🔌 Available endpoints: {', '.join(list(_registered_agents.keys()))}")
1534
- uvicorn.run(_shared_app, host=host, port=port, log_level="debug" if debug else "info")
1543
+ print(f"🔌 Available endpoints: {', '.join(list(_registered_agents[port].keys()))}")
1544
+ uvicorn.run(_shared_apps[port], host=host, port=port, log_level="debug" if debug else "info")
1535
1545
  except Exception as e:
1536
1546
  logging.error(f"Error starting server: {str(e)}", exc_info=True)
1537
1547
  print(f"❌ Error starting server: {str(e)}")
@@ -1545,7 +1555,7 @@ Your Goal: {self.goal}
1545
1555
  else:
1546
1556
  # If server is already running, wait a moment to make sure the endpoint is registered
1547
1557
  time.sleep(0.1)
1548
- print(f"🔌 Available endpoints: {', '.join(list(_registered_agents.keys()))}")
1558
+ print(f"🔌 Available endpoints on port {port}: {', '.join(list(_registered_agents[port].keys()))}")
1549
1559
 
1550
1560
  # Get the stack frame to check if this is the last launch() call in the script
1551
1561
  import inspect
@@ -1571,18 +1581,19 @@ Your Goal: {self.goal}
1571
1581
  # If this is the last launch call, block the main thread
1572
1582
  if not has_more_launches:
1573
1583
  try:
1574
- print("\nAll agents registered. Press Ctrl+C to stop the server.")
1584
+ print("\nAll agents registered. Press Ctrl+C to stop the servers.")
1575
1585
  while True:
1576
1586
  time.sleep(1)
1577
1587
  except KeyboardInterrupt:
1578
- print("\nServer stopped")
1588
+ print("\nServers stopped")
1579
1589
  except Exception as e:
1580
1590
  # If something goes wrong with detection, block anyway to be safe
1581
1591
  logging.error(f"Error in launch detection: {e}")
1582
1592
  try:
1593
+ print("\nKeeping servers alive. Press Ctrl+C to stop.")
1583
1594
  while True:
1584
1595
  time.sleep(1)
1585
1596
  except KeyboardInterrupt:
1586
- print("\nServer stopped")
1597
+ print("\nServers stopped")
1587
1598
 
1588
1599
  return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: praisonaiagents
3
- Version: 0.0.80
3
+ Version: 0.0.81
4
4
  Summary: Praison AI agents for completing complex tasks with Self Reflection Agents
5
5
  Author: Mervin Praison
6
6
  Requires-Dist: pydantic
@@ -1,7 +1,7 @@
1
1
  praisonaiagents/__init__.py,sha256=Z2_rSA6mYozz0r3ioUgKzl3QV8uWRDS_QaqPg2oGjqg,1324
2
2
  praisonaiagents/main.py,sha256=l29nGEbV2ReBi4szURbnH0Fk0w2F_QZTmECysyZjYcA,15066
3
3
  praisonaiagents/agent/__init__.py,sha256=j0T19TVNbfZcClvpbZDDinQxZ0oORgsMrMqx16jZ-bA,128
4
- praisonaiagents/agent/agent.py,sha256=OOP_05mOMoHNkeElQWqH9jKOFUivlIjZ_vZJWLhIkSc,75089
4
+ praisonaiagents/agent/agent.py,sha256=mTzu6481jEqE7XoLbwhaWQ56lV16aTxPvDO4xjMH8dE,75743
5
5
  praisonaiagents/agent/image_agent.py,sha256=-5MXG594HVwSpFMcidt16YBp7udtik-Cp7eXlzLE1fY,8696
6
6
  praisonaiagents/agents/__init__.py,sha256=_1d6Pqyk9EoBSo7E68sKyd1jDRlN1vxvVIRpoMc0Jcw,168
7
7
  praisonaiagents/agents/agents.py,sha256=ABMQW07fH8HgY0adiwollDB5DQJZcf7uGhu4njiyIVM,49026
@@ -40,7 +40,7 @@ praisonaiagents/tools/xml_tools.py,sha256=iYTMBEk5l3L3ryQ1fkUnNVYK-Nnua2Kx2S0dxN
40
40
  praisonaiagents/tools/yaml_tools.py,sha256=uogAZrhXV9O7xvspAtcTfpKSQYL2nlOTvCQXN94-G9A,14215
41
41
  praisonaiagents/tools/yfinance_tools.py,sha256=s2PBj_1v7oQnOobo2fDbQBACEHl61ftG4beG6Z979ZE,8529
42
42
  praisonaiagents/tools/train/data/generatecot.py,sha256=H6bNh-E2hqL5MW6kX3hqZ05g9ETKN2-kudSjiuU_SD8,19403
43
- praisonaiagents-0.0.80.dist-info/METADATA,sha256=MAc45qEZryYHTSeN-iQ0Ia90WSHgKEDmu9ulXvfY8cw,1149
44
- praisonaiagents-0.0.80.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
45
- praisonaiagents-0.0.80.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
46
- praisonaiagents-0.0.80.dist-info/RECORD,,
43
+ praisonaiagents-0.0.81.dist-info/METADATA,sha256=Os4lVkWeygFi1A1TWk2jgH1pvuNx4jWXVr4alOkSB1A,1149
44
+ praisonaiagents-0.0.81.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
45
+ praisonaiagents-0.0.81.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
46
+ praisonaiagents-0.0.81.dist-info/RECORD,,