Duibonduil commited on
Commit
47aff61
·
verified ·
1 Parent(s): 4e067f2

Upload 4 files

Browse files
aworld/__init__.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding: utf-8
2
+ # Copyright (c) 2025 inclusionAI.
3
+ import os
4
+
5
+ try:
6
+ from aworld.utils.import_package import import_package
7
+
8
+ import_package("dotenv", install_name="python-dotenv")
9
+ from dotenv import load_dotenv
10
+
11
+ sucess = load_dotenv()
12
+ if not sucess:
13
+ load_dotenv(os.path.join(os.getcwd(), ".env"))
14
+ except Exception as e:
15
+ print(e)
aworld/__main__.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # coding: utf-8
2
+ # Copyright (c) 2025 inclusionAI.
3
+
4
+ from .cmd.cli import main
5
+
6
+ if __name__ == "__main__":
7
+ main()
aworld/runner.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding: utf-8
2
+ # Copyright (c) 2025 inclusionAI.
3
+ import asyncio
4
+ from typing import List, Dict, Union
5
+
6
+ from aworld.config import RunConfig
7
+ from aworld.config.conf import TaskConfig
8
+ from aworld.agents.llm_agent import Agent
9
+ from aworld.core.agent.swarm import Swarm
10
+ from aworld.core.common import Config
11
+ from aworld.core.task import Task, TaskResponse, Runner
12
+ from aworld.output import StreamingOutputs
13
+ from aworld.runners.utils import choose_runners, execute_runner
14
+ from aworld.utils.common import sync_exec
15
+
16
+
17
+ class Runners:
18
+ """Unified entrance to the utility class of the runnable task of execution."""
19
+
20
+ @staticmethod
21
+ def streamed_run_task(task: Task) -> StreamingOutputs:
22
+ """Run the task in stream output."""
23
+ if not task.conf:
24
+ task.conf = TaskConfig()
25
+
26
+ streamed_result = StreamingOutputs(
27
+ input=task.input,
28
+ usage={},
29
+ is_complete=False
30
+ )
31
+ task.outputs = streamed_result
32
+
33
+ streamed_result._run_impl_task = asyncio.create_task(
34
+ Runners.run_task(task)
35
+ )
36
+ return streamed_result
37
+
38
+ @staticmethod
39
+ async def run_task(task: Union[Task, List[Task]], run_conf: RunConfig = None) -> Dict[str, TaskResponse]:
40
+ """Run tasks for some complex scenarios where agents cannot be directly used.
41
+
42
+ Args:
43
+ task: User task define.
44
+ run_conf:
45
+ """
46
+ if isinstance(task, Task):
47
+ task = [task]
48
+
49
+ runners: List[Runner] = await choose_runners(task)
50
+ return await execute_runner(runners, run_conf)
51
+
52
+ @staticmethod
53
+ def sync_run_task(task: Union[Task, List[Task]], run_conf: Config = None) -> Dict[str, TaskResponse]:
54
+ return sync_exec(Runners.run_task, task=task, run_conf=run_conf)
55
+
56
+ @staticmethod
57
+ def sync_run(
58
+ input: str,
59
+ agent: Agent = None,
60
+ swarm: Swarm = None,
61
+ tool_names: List[str] = [],
62
+ session_id: str = None
63
+ ) -> TaskResponse:
64
+ return sync_exec(
65
+ Runners.run,
66
+ input=input,
67
+ agent=agent,
68
+ swarm=swarm,
69
+ tool_names=tool_names,
70
+ session_id=session_id
71
+ )
72
+
73
+ @staticmethod
74
+ async def run(
75
+ input: str,
76
+ agent: Agent = None,
77
+ swarm: Swarm = None,
78
+ tool_names: List[str] = [],
79
+ session_id: str = None
80
+ ) -> TaskResponse:
81
+ """Run agent directly with input and tool names.
82
+
83
+ Args:
84
+ input: User query.
85
+ agent: An agent with AI model configured, prompts, tools, mcp servers and other agents.
86
+ swarm: Multi-agent topo.
87
+ tool_names: Tool name list.
88
+ session_id: Session id.
89
+
90
+ Returns:
91
+ TaskResponse: Task response.
92
+ """
93
+ if agent and swarm:
94
+ raise ValueError("`agent` and `swarm` only choose one.")
95
+
96
+ if not input:
97
+ raise ValueError('`input` is empty.')
98
+
99
+ if agent:
100
+ agent.task = input
101
+ swarm = Swarm(agent)
102
+
103
+ task = Task(input=input, swarm=swarm, tool_names=tool_names,
104
+ event_driven=swarm.event_driven, session_id=session_id)
105
+ res = await Runners.run_task(task)
106
+ return res.get(task.id)
aworld/version_gen.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding: utf-8
2
+ # Copyright (c) 2025 inclusionAI.
3
+
4
+ import os
5
+ import getpass
6
+ import time
7
+
8
+ __version__ = '0.2.2'
9
+
10
+ version_template = \
11
+ """# auto generated
12
+ class VersionInfo:
13
+ BUILD_DATE = "{BUILD_DATE}"
14
+ BUILD_VERSION = "{BUILD_VERSION}"
15
+ BUILD_USER = "{BUILD_USER}"
16
+ SCENARIO = "{SCENARIO}"
17
+ """
18
+
19
+
20
+ def generate_version_info(directory_path: str = None, scenario: str = "", version: str = None):
21
+ if directory_path is None:
22
+ directory_path = os.path.dirname(__file__)
23
+ with open(os.path.join(directory_path, "version_info.py"), "w") as f:
24
+ version_info = _build_version_template(scenario=scenario, version=version)
25
+ f.write(version_info)
26
+
27
+
28
+ def _build_version_template(scenario: str = "", version: str = None) -> str:
29
+ if version is None:
30
+ version = __version__
31
+ return version_template.format(
32
+ BUILD_USER=getpass.getuser(),
33
+ BUILD_VERSION=version,
34
+ BUILD_DATE=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
35
+ SCENARIO=scenario,
36
+ )