-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
156 lines (137 loc) · 4.77 KB
/
main.py
File metadata and controls
156 lines (137 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT
"""
Entry point script for the Morgana project.
"""
import argparse
import asyncio
from InquirerPy import inquirer
from src.config.questions import BUILT_IN_QUESTIONS, BUILT_IN_QUESTIONS_ZH_CN
from src.workflow import run_agent_workflow_async
def ask(
question,
debug=False,
max_plan_iterations=1,
max_step_num=3,
enable_background_investigation=True,
):
"""Run the agent workflow with the given question.
Args:
question: The user's query or request
debug: If True, enables debug level logging
max_plan_iterations: Maximum number of plan iterations
max_step_num: Maximum number of steps in a plan
enable_background_investigation: If True, performs web search before planning to enhance context
"""
asyncio.run(
run_agent_workflow_async(
user_input=question,
debug=debug,
max_plan_iterations=max_plan_iterations,
max_step_num=max_step_num,
enable_background_investigation=enable_background_investigation,
)
)
def main(
debug=False,
max_plan_iterations=1,
max_step_num=3,
enable_background_investigation=True,
):
"""Interactive mode with built-in questions.
Args:
enable_background_investigation: If True, performs web search before planning to enhance context
debug: If True, enables debug level logging
max_plan_iterations: Maximum number of plan iterations
max_step_num: Maximum number of steps in a plan
"""
# First select language
language = inquirer.select(
message="Select language / 选择语言:",
choices=["English", "中文"],
).execute()
# Choose questions based on language
questions = (
BUILT_IN_QUESTIONS if language == "English" else BUILT_IN_QUESTIONS_ZH_CN
)
ask_own_option = (
"[Ask my own question]" if language == "English" else "[自定义问题]"
)
# Select a question
initial_question = inquirer.select(
message=(
"What do you want to know?" if language == "English" else "您想了解什么?"
),
choices=[ask_own_option] + questions,
).execute()
if initial_question == ask_own_option:
initial_question = inquirer.text(
message=(
"What do you want to know?"
if language == "English"
else "您想了解什么?"
),
).execute()
# Pass all parameters to ask function
ask(
question=initial_question,
debug=debug,
max_plan_iterations=max_plan_iterations,
max_step_num=max_step_num,
enable_background_investigation=enable_background_investigation,
)
if __name__ == "__main__":
# Set up argument parser
parser = argparse.ArgumentParser(description="Run the Morgana agent.")
parser.add_argument("query", nargs="*", help="The query to process")
parser.add_argument(
"--interactive",
action="store_true",
help="Run in interactive mode with built-in questions",
)
parser.add_argument(
"--max_plan_iterations",
type=int,
default=1,
help="Maximum number of plan iterations (default: 1)",
)
parser.add_argument(
"--max_step_num",
type=int,
default=3,
help="Maximum number of steps in a plan (default: 3)",
)
parser.add_argument("--debug", action="store_true", help="Enable debug logging")
parser.add_argument(
"--no-background-investigation",
action="store_false",
dest="enable_background_investigation",
help="Disable background investigation before planning",
)
args = parser.parse_args()
if args.interactive:
# Pass command line arguments to main function
main(
debug=args.debug,
max_plan_iterations=args.max_plan_iterations,
max_step_num=args.max_step_num,
enable_background_investigation=args.enable_background_investigation,
)
else:
# Parse user input from command line arguments or user input
if args.query:
user_query = " ".join(args.query)
else:
# Loop until user provides non-empty input
while True:
user_query = input("Enter your query: ")
if user_query is not None and user_query != "":
break
# Run the agent workflow with the provided parameters
ask(
question=user_query,
debug=args.debug,
max_plan_iterations=args.max_plan_iterations,
max_step_num=args.max_step_num,
enable_background_investigation=args.enable_background_investigation,
)