praisonaiagents 0.0.78__py3-none-any.whl → 0.0.79__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.
@@ -22,16 +22,16 @@ import inspect
22
22
  import uuid
23
23
  from dataclasses import dataclass
24
24
 
25
+ # Global variables for API server
26
+ _server_started = False
27
+ _registered_agents = {}
28
+ _shared_app = None
29
+
25
30
  # Don't import FastAPI dependencies here - use lazy loading instead
26
31
 
27
32
  if TYPE_CHECKING:
28
33
  from ..task.task import Task
29
34
 
30
- # Shared variables for API server
31
- _shared_app = None
32
- _server_started = False
33
- _registered_agents = {}
34
-
35
35
  @dataclass
36
36
  class ChatCompletionMessage:
37
37
  content: str
@@ -1408,7 +1408,7 @@ Your Goal: {self.goal}
1408
1408
  logging.error(f"Error in execute_tool_async: {str(e)}", exc_info=True)
1409
1409
  return {"error": f"Error in execute_tool_async: {str(e)}"}
1410
1410
 
1411
- def launch(self, path: str = '/', port: int = 8000, host: str = '0.0.0.0', autostart: bool = True, debug: bool = False, blocking: bool = True):
1411
+ def launch(self, path: str = '/', port: int = 8000, host: str = '0.0.0.0', debug: bool = False):
1412
1412
  """
1413
1413
  Launch the agent as an HTTP API endpoint.
1414
1414
 
@@ -1416,9 +1416,7 @@ Your Goal: {self.goal}
1416
1416
  path: API endpoint path (default: '/')
1417
1417
  port: Server port (default: 8000)
1418
1418
  host: Server host (default: '0.0.0.0')
1419
- autostart: Whether to start the server automatically (default: True)
1420
1419
  debug: Enable debug mode for uvicorn (default: False)
1421
- blocking: If True, blocks the main thread to keep the server running (default: True)
1422
1420
 
1423
1421
  Returns:
1424
1422
  None
@@ -1431,6 +1429,8 @@ Your Goal: {self.goal}
1431
1429
  from fastapi import FastAPI, HTTPException, Request
1432
1430
  from fastapi.responses import JSONResponse
1433
1431
  from pydantic import BaseModel
1432
+ import threading
1433
+ import time
1434
1434
 
1435
1435
  # Define the request model here since we need pydantic
1436
1436
  class AgentQuery(BaseModel):
@@ -1458,6 +1458,11 @@ Your Goal: {self.goal}
1458
1458
  @_shared_app.get("/")
1459
1459
  async def root():
1460
1460
  return {"message": "Welcome to PraisonAI Agents API. See /docs for usage."}
1461
+
1462
+ # Add healthcheck endpoint
1463
+ @_shared_app.get("/health")
1464
+ async def healthcheck():
1465
+ return {"status": "ok", "agents": list(_registered_agents.keys())}
1461
1466
 
1462
1467
  # Normalize path to ensure it starts with /
1463
1468
  if not path.startswith('/'):
@@ -1516,47 +1521,68 @@ Your Goal: {self.goal}
1516
1521
 
1517
1522
  print(f"🚀 Agent '{self.name}' available at http://{host}:{port}{path}")
1518
1523
 
1519
- # Start the server if this is the first launch call and autostart is True
1520
- if autostart and not _server_started:
1524
+ # Start the server if it's not already running
1525
+ if not _server_started:
1521
1526
  _server_started = True
1522
1527
 
1523
- # Add healthcheck endpoint
1524
- @_shared_app.get("/health")
1525
- async def healthcheck():
1526
- return {"status": "ok", "agents": list(_registered_agents.keys())}
1527
-
1528
- # Start the server in a separate thread to not block execution
1529
- import threading
1528
+ # Start the server in a separate thread
1530
1529
  def run_server():
1531
1530
  try:
1531
+ print(f"✅ FastAPI server started at http://{host}:{port}")
1532
+ print(f"📚 API documentation available at http://{host}:{port}/docs")
1533
+ print(f"🔌 Available endpoints: {', '.join(list(_registered_agents.keys()))}")
1532
1534
  uvicorn.run(_shared_app, host=host, port=port, log_level="debug" if debug else "info")
1533
1535
  except Exception as e:
1534
1536
  logging.error(f"Error starting server: {str(e)}", exc_info=True)
1535
1537
  print(f"❌ Error starting server: {str(e)}")
1536
1538
 
1539
+ # Run server in a background thread
1537
1540
  server_thread = threading.Thread(target=run_server, daemon=True)
1538
1541
  server_thread.start()
1539
1542
 
1540
- # Give the server a moment to start up
1541
- import time
1543
+ # Wait for a moment to allow the server to start and register endpoints
1542
1544
  time.sleep(0.5)
1545
+ else:
1546
+ # If server is already running, wait a moment to make sure the endpoint is registered
1547
+ time.sleep(0.1)
1548
+ print(f"🔌 Available endpoints: {', '.join(list(_registered_agents.keys()))}")
1549
+
1550
+ # Get the stack frame to check if this is the last launch() call in the script
1551
+ import inspect
1552
+ stack = inspect.stack()
1553
+
1554
+ # If this is called from a Python script (not interactive), try to detect if it's the last launch call
1555
+ if len(stack) > 1 and stack[1].filename.endswith('.py'):
1556
+ caller_frame = stack[1]
1557
+ caller_line = caller_frame.lineno
1543
1558
 
1544
- print(f"✅ FastAPI server started at http://{host}:{port}")
1545
- print(f"📚 API documentation available at http://{host}:{port}/docs")
1546
-
1547
- # If blocking is True, keep the main thread alive
1548
- if blocking:
1549
- print("\nServer is running in blocking mode. Press Ctrl+C to stop...")
1559
+ try:
1560
+ # Read the file to check if there are more launch calls after this one
1561
+ with open(caller_frame.filename, 'r') as f:
1562
+ lines = f.readlines()
1563
+
1564
+ # Check if there are more launch() calls after the current line
1565
+ has_more_launches = False
1566
+ for line in lines[caller_line:]:
1567
+ if '.launch(' in line and not line.strip().startswith('#'):
1568
+ has_more_launches = True
1569
+ break
1570
+
1571
+ # If this is the last launch call, block the main thread
1572
+ if not has_more_launches:
1573
+ try:
1574
+ print("\nAll agents registered. Press Ctrl+C to stop the server.")
1575
+ while True:
1576
+ time.sleep(1)
1577
+ except KeyboardInterrupt:
1578
+ print("\nServer stopped")
1579
+ except Exception as e:
1580
+ # If something goes wrong with detection, block anyway to be safe
1581
+ logging.error(f"Error in launch detection: {e}")
1550
1582
  try:
1551
1583
  while True:
1552
1584
  time.sleep(1)
1553
1585
  except KeyboardInterrupt:
1554
1586
  print("\nServer stopped")
1555
- else:
1556
- # Note for non-blocking mode
1557
- print("\nNote: Server is running in a background thread. To keep it alive, either:")
1558
- print("1. Set blocking=True when calling launch()")
1559
- print("2. Keep your main application running")
1560
- print("3. Use a loop in your code to prevent the program from exiting")
1561
-
1587
+
1562
1588
  return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: praisonaiagents
3
- Version: 0.0.78
3
+ Version: 0.0.79
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=mkZOHL_qgZaiX_DXTgiDlMIfjTmrqeMpi088VCC_YOo,73946
4
+ praisonaiagents/agent/agent.py,sha256=OOP_05mOMoHNkeElQWqH9jKOFUivlIjZ_vZJWLhIkSc,75089
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=uAOHyn77noFvg3sYVFRhQUuc1LDpCMpfLND8CKOXAd4,37971
@@ -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.78.dist-info/METADATA,sha256=VwX1r4Ib2OxhTYVqSHpEluxljiGzNy7eifYi6wBRbTk,1149
44
- praisonaiagents-0.0.78.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
45
- praisonaiagents-0.0.78.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
46
- praisonaiagents-0.0.78.dist-info/RECORD,,
43
+ praisonaiagents-0.0.79.dist-info/METADATA,sha256=kfbFrfIzL7AMat_CvuzqwaLAakTuDZ3IspnIW4T5Mwo,1149
44
+ praisonaiagents-0.0.79.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
45
+ praisonaiagents-0.0.79.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
46
+ praisonaiagents-0.0.79.dist-info/RECORD,,