Skip to content

Commit e9be13f

Browse files
committed
Enhance CLI with Direct Prompt Handling and Framework Flexibility
- Added direct prompt handling in CLI for immediate task execution - Implemented fallback mechanism to support multiple AI agent frameworks (PraisonAI, CrewAI, AutoGen) - Updated CLI parsing to handle various input scenarios - Simplified agent initialization for direct prompts - Improved error messaging for framework installation - Bumped package version to 2.0.62
1 parent 2ab8ea0 commit e9be13f

File tree

8 files changed

+83
-1896
lines changed

8 files changed

+83
-1896
lines changed

.cursorrules

+8-1,885
Large diffs are not rendered by default.

docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.11-slim
22
WORKDIR /app
33
COPY . .
4-
RUN pip install flask praisonai==2.0.61 gunicorn markdown
4+
RUN pip install flask praisonai==2.0.62 gunicorn markdown
55
EXPOSE 8080
66
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]

docs/api/praisonai/deploy.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h2 id="raises">Raises</h2>
110110
file.write(&#34;FROM python:3.11-slim\n&#34;)
111111
file.write(&#34;WORKDIR /app\n&#34;)
112112
file.write(&#34;COPY . .\n&#34;)
113-
file.write(&#34;RUN pip install flask praisonai==2.0.61 gunicorn markdown\n&#34;)
113+
file.write(&#34;RUN pip install flask praisonai==2.0.62 gunicorn markdown\n&#34;)
114114
file.write(&#34;EXPOSE 8080\n&#34;)
115115
file.write(&#39;CMD [&#34;gunicorn&#34;, &#34;-b&#34;, &#34;0.0.0.0:8080&#34;, &#34;api:app&#34;]\n&#39;)
116116

praisonai.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Praisonai < Formula
33

44
desc "AI tools for various AI applications"
55
homepage "https://github.com/MervinPraison/PraisonAI"
6-
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/2.0.61.tar.gz"
6+
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/2.0.62.tar.gz"
77
sha256 "1828fb9227d10f991522c3f24f061943a254b667196b40b1a3e4a54a8d30ce32" # Replace with actual SHA256 checksum
88
license "MIT"
99

praisonai/cli.py

+68-4
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,16 @@ def main(self):
148148
if args.command:
149149
if args.command.startswith("tests.test"): # Argument used for testing purposes
150150
print("test")
151+
return "test"
151152
else:
152153
self.agent_file = args.command
154+
elif hasattr(args, 'direct_prompt') and args.direct_prompt:
155+
result = self.handle_direct_prompt(args.direct_prompt)
156+
print(result)
157+
return result
158+
else:
159+
# Default to agents.yaml if no command provided
160+
self.agent_file = "agents.yaml"
153161

154162
if args.deploy:
155163
from .deploy import CloudDeployer
@@ -285,12 +293,15 @@ def parse_args(self):
285293
"""
286294
Parse the command-line arguments for the PraisonAI CLI.
287295
"""
296+
# Define special commands
297+
special_commands = ['chat', 'code', 'call', 'realtime', 'train', 'ui']
298+
288299
parser = argparse.ArgumentParser(prog="praisonai", description="praisonAI command-line interface")
289300
parser.add_argument("--framework", choices=["crewai", "autogen", "praisonai"], help="Specify the framework")
290301
parser.add_argument("--ui", choices=["chainlit", "gradio"], help="Specify the UI framework (gradio or chainlit).")
291302
parser.add_argument("--auto", nargs=argparse.REMAINDER, help="Enable auto mode and pass arguments for it")
292303
parser.add_argument("--init", nargs=argparse.REMAINDER, help="Initialize agents with optional topic")
293-
parser.add_argument("command", nargs="?", help="Command to run")
304+
parser.add_argument("command", nargs="?", help="Command to run or direct prompt")
294305
parser.add_argument("--deploy", action="store_true", help="Deploy the application")
295306
parser.add_argument("--model", type=str, help="Model name")
296307
parser.add_argument("--hf", type=str, help="Hugging Face model name")
@@ -301,6 +312,7 @@ def parse_args(self):
301312
parser.add_argument("--public", action="store_true", help="Use ngrok to expose the server publicly (only with --call)")
302313
args, unknown_args = parser.parse_known_args()
303314

315+
# Handle special cases first
304316
if unknown_args and unknown_args[0] == '-b' and unknown_args[1] == 'api:app':
305317
args.command = 'agents.yaml'
306318
if args.command == 'api:app' or args.command == '/app/api:app':
@@ -331,9 +343,7 @@ def parse_args(self):
331343
call_module.main(call_args)
332344
sys.exit(0)
333345

334-
# Handle special commands first
335-
special_commands = ['chat', 'code', 'call', 'realtime', 'train', 'ui']
336-
346+
# Handle special commands
337347
if args.command in special_commands:
338348
if args.command == 'chat':
339349
if not CHAINLIT_AVAILABLE:
@@ -402,8 +412,62 @@ def parse_args(self):
402412
print("pip install praisonaiagents # For PraisonAIAgents\n")
403413
sys.exit(1)
404414

415+
# Handle direct prompt if command is not a special command or file
416+
if args.command and not args.command.endswith('.yaml') and args.command not in special_commands:
417+
args.direct_prompt = args.command
418+
args.command = None
419+
405420
return args
406421

422+
def handle_direct_prompt(self, prompt):
423+
"""
424+
Handle direct prompt by creating a single agent and running it.
425+
"""
426+
if PRAISONAI_AVAILABLE:
427+
agent = PraisonAgent(
428+
name="DirectAgent",
429+
role="Assistant",
430+
goal="Complete the given task",
431+
backstory="You are a helpful AI assistant"
432+
)
433+
agent.start(prompt)
434+
return ""
435+
elif CREWAI_AVAILABLE:
436+
agent = Agent(
437+
name="DirectAgent",
438+
role="Assistant",
439+
goal="Complete the given task",
440+
backstory="You are a helpful AI assistant"
441+
)
442+
task = Task(
443+
description=prompt,
444+
agent=agent
445+
)
446+
crew = Crew(
447+
agents=[agent],
448+
tasks=[task]
449+
)
450+
return crew.kickoff()
451+
elif AUTOGEN_AVAILABLE:
452+
config_list = self.config_list
453+
assistant = autogen.AssistantAgent(
454+
name="DirectAgent",
455+
llm_config={"config_list": config_list}
456+
)
457+
user_proxy = autogen.UserProxyAgent(
458+
name="UserProxy",
459+
code_execution_config={"work_dir": "coding"}
460+
)
461+
user_proxy.initiate_chat(assistant, message=prompt)
462+
return "Task completed"
463+
else:
464+
print("[red]ERROR: No framework is installed. Please install at least one framework:[/red]")
465+
print("\npip install \"praisonai\\[crewai]\" # For CrewAI")
466+
print("pip install \"praisonai\\[autogen]\" # For AutoGen")
467+
print("pip install \"praisonai\\[crewai,autogen]\" # For both frameworks\n")
468+
print("pip install praisonaiagents # For PraisonAIAgents\n")
469+
sys.exit(1)
470+
407471
def create_chainlit_chat_interface(self):
408472
"""
409473
Create a Chainlit interface for the chat application.

praisonai/deploy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def create_dockerfile(self):
5656
file.write("FROM python:3.11-slim\n")
5757
file.write("WORKDIR /app\n")
5858
file.write("COPY . .\n")
59-
file.write("RUN pip install flask praisonai==2.0.61 gunicorn markdown\n")
59+
file.write("RUN pip install flask praisonai==2.0.62 gunicorn markdown\n")
6060
file.write("EXPOSE 8080\n")
6161
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
6262

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "PraisonAI"
3-
version = "2.0.61"
3+
version = "2.0.62"
44
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human-agent collaboration."
55
readme = "README.md"
66
license = ""
@@ -84,7 +84,7 @@ autogen = ["pyautogen>=0.2.19", "praisonai-tools>=0.0.7", "crewai"]
8484

8585
[tool.poetry]
8686
name = "PraisonAI"
87-
version = "2.0.61"
87+
version = "2.0.62"
8888
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human–agent collaboration."
8989
authors = ["Mervin Praison"]
9090
license = ""

uv.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)