lionagi 0.0.315__tar.gz → 0.1.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {lionagi-0.0.315/lionagi.egg-info → lionagi-0.1.0}/PKG-INFO +1 -1
- lionagi-0.1.0/lionagi/core/__init__.py +26 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/agent/base_agent.py +26 -30
- lionagi-0.0.315/lionagi/core/branch/base_branch.py → lionagi-0.1.0/lionagi/core/branch/base.py +13 -14
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/branch/branch.py +22 -20
- lionagi-0.0.315/lionagi/core/branch/branch_flow_mixin.py → lionagi-0.1.0/lionagi/core/branch/flow_mixin.py +6 -6
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/branch/util.py +1 -1
- lionagi-0.1.0/lionagi/core/direct/__init__.py +19 -0
- lionagi-0.1.0/lionagi/core/direct/cot.py +123 -0
- lionagi-0.1.0/lionagi/core/direct/plan.py +164 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/direct/predict.py +13 -9
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/direct/react.py +12 -8
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/direct/score.py +4 -4
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/direct/select.py +4 -4
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/direct/utils.py +23 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/direct/vote.py +2 -2
- lionagi-0.1.0/lionagi/core/execute/base_executor.py +50 -0
- lionagi-0.1.0/lionagi/core/execute/branch_executor.py +233 -0
- lionagi-0.1.0/lionagi/core/execute/instruction_map_executor.py +131 -0
- lionagi-0.1.0/lionagi/core/execute/structure_executor.py +218 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/flow/monoflow/ReAct.py +4 -4
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/flow/monoflow/chat.py +6 -6
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/flow/monoflow/chat_mixin.py +24 -34
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/flow/monoflow/followup.py +4 -4
- lionagi-0.1.0/lionagi/core/flow/polyflow/__init__.py +1 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/flow/polyflow/chat.py +15 -12
- lionagi-0.0.315/lionagi/core/prompt/action_template.py → lionagi-0.1.0/lionagi/core/form/action_form.py +2 -2
- {lionagi-0.0.315/lionagi/core/prompt → lionagi-0.1.0/lionagi/core/form}/field_validator.py +40 -31
- lionagi-0.1.0/lionagi/core/form/form.py +302 -0
- lionagi-0.1.0/lionagi/core/form/mixin.py +214 -0
- lionagi-0.0.315/lionagi/core/prompt/scored_template.py → lionagi-0.1.0/lionagi/core/form/scored_form.py +2 -2
- lionagi-0.1.0/lionagi/core/generic/__init__.py +37 -0
- lionagi-0.1.0/lionagi/core/generic/action.py +26 -0
- lionagi-0.1.0/lionagi/core/generic/component.py +457 -0
- lionagi-0.1.0/lionagi/core/generic/condition.py +44 -0
- lionagi-0.1.0/lionagi/core/generic/data_logger.py +305 -0
- lionagi-0.1.0/lionagi/core/generic/edge.py +110 -0
- lionagi-0.1.0/lionagi/core/generic/mail.py +90 -0
- lionagi-0.1.0/lionagi/core/generic/mailbox.py +36 -0
- lionagi-0.1.0/lionagi/core/generic/node.py +285 -0
- lionagi-0.1.0/lionagi/core/generic/relation.py +70 -0
- lionagi-0.1.0/lionagi/core/generic/signal.py +22 -0
- lionagi-0.1.0/lionagi/core/generic/structure.py +362 -0
- lionagi-0.1.0/lionagi/core/generic/transfer.py +20 -0
- lionagi-0.1.0/lionagi/core/generic/work.py +40 -0
- lionagi-0.1.0/lionagi/core/graph/graph.py +126 -0
- lionagi-0.1.0/lionagi/core/graph/tree.py +190 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/mail/mail_manager.py +12 -10
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/mail/schema.py +9 -2
- lionagi-0.1.0/lionagi/core/messages/schema.py +325 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/session/session.py +25 -23
- lionagi-0.1.0/lionagi/core/tool/__init__.py +5 -0
- lionagi-0.1.0/lionagi/core/tool/tool.py +28 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/tool/tool_manager.py +75 -75
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/chunker/chunk.py +7 -7
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/config/oai_configs.py +4 -4
- lionagi-0.1.0/lionagi/integrations/loader/__init__.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/loader/load.py +6 -6
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/loader/load_util.py +8 -8
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/libs/ln_api.py +3 -3
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/libs/ln_parse.py +43 -6
- lionagi-0.1.0/lionagi/libs/ln_validate.py +288 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/libs/sys_util.py +28 -6
- lionagi-0.1.0/lionagi/tests/__init__.py +0 -0
- lionagi-0.1.0/lionagi/tests/integrations/__init__.py +0 -0
- lionagi-0.1.0/lionagi/tests/libs/__init__.py +0 -0
- lionagi-0.1.0/lionagi/tests/libs/test_async.py +0 -0
- lionagi-0.1.0/lionagi/tests/libs/test_field_validators.py +353 -0
- lionagi-0.1.0/lionagi/tests/test_core/__init__.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/tests/test_core/test_base_branch.py +0 -1
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/tests/test_core/test_branch.py +3 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/tests/test_core/test_session_base_util.py +1 -0
- lionagi-0.1.0/lionagi/version.py +1 -0
- {lionagi-0.0.315 → lionagi-0.1.0/lionagi.egg-info}/PKG-INFO +1 -1
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi.egg-info/SOURCES.txt +45 -30
- lionagi-0.0.315/lionagi/core/__init__.py +0 -15
- lionagi-0.0.315/lionagi/core/agent/__init__.py +0 -3
- lionagi-0.0.315/lionagi/core/branch/__init__.py +0 -4
- lionagi-0.0.315/lionagi/core/branch/executable_branch.py +0 -347
- lionagi-0.0.315/lionagi/core/direct/__init__.py +0 -7
- lionagi-0.0.315/lionagi/core/direct/cot.py +0 -1
- lionagi-0.0.315/lionagi/core/flow/polyflow/__init__.py +0 -1
- lionagi-0.0.315/lionagi/core/mail/__init__.py +0 -8
- lionagi-0.0.315/lionagi/core/messages/__init__.py +0 -3
- lionagi-0.0.315/lionagi/core/messages/schema.py +0 -533
- lionagi-0.0.315/lionagi/core/prompt/prompt_template.py +0 -312
- lionagi-0.0.315/lionagi/core/schema/__init__.py +0 -22
- lionagi-0.0.315/lionagi/core/schema/action_node.py +0 -29
- lionagi-0.0.315/lionagi/core/schema/base_mixin.py +0 -296
- lionagi-0.0.315/lionagi/core/schema/base_node.py +0 -199
- lionagi-0.0.315/lionagi/core/schema/condition.py +0 -24
- lionagi-0.0.315/lionagi/core/schema/data_logger.py +0 -354
- lionagi-0.0.315/lionagi/core/schema/data_node.py +0 -93
- lionagi-0.0.315/lionagi/core/schema/prompt_template.py +0 -67
- lionagi-0.0.315/lionagi/core/schema/structure.py +0 -912
- lionagi-0.0.315/lionagi/core/session/__init__.py +0 -3
- lionagi-0.0.315/lionagi/core/tool/__init__.py +0 -3
- lionagi-0.0.315/lionagi/core/tool/manual.py +0 -1
- lionagi-0.0.315/lionagi/version.py +0 -1
- {lionagi-0.0.315 → lionagi-0.1.0}/LICENSE +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/README.md +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/README.rst +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/__init__.py +0 -0
- {lionagi-0.0.315/lionagi/core/branch/base → lionagi-0.1.0/lionagi/core/agent}/__init__.py +0 -0
- {lionagi-0.0.315/lionagi/core/flow → lionagi-0.1.0/lionagi/core/branch}/__init__.py +0 -0
- /lionagi-0.0.315/lionagi/core/direct/plan.py → /lionagi-0.1.0/lionagi/core/branch/executable_branch.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/direct/sentiment.py +0 -0
- {lionagi-0.0.315/lionagi/core/flow/base → lionagi-0.1.0/lionagi/core/execute}/__init__.py +0 -0
- {lionagi-0.0.315/lionagi/core/prompt → lionagi-0.1.0/lionagi/core/flow}/__init__.py +0 -0
- {lionagi-0.0.315/lionagi/core/flow/base → lionagi-0.1.0/lionagi/core/flow}/baseflow.py +0 -0
- /lionagi-0.0.315/lionagi/integrations/bridge/langchain_/__init__.py → /lionagi-0.1.0/lionagi/core/flow/mono_chat_mixin.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/core/flow/monoflow/__init__.py +0 -0
- {lionagi-0.0.315/lionagi/integrations/bridge/llamaindex_ → lionagi-0.1.0/lionagi/core/form}/__init__.py +0 -0
- {lionagi-0.0.315/lionagi/integrations/bridge/pydantic_ → lionagi-0.1.0/lionagi/core/graph}/__init__.py +0 -0
- {lionagi-0.0.315/lionagi/integrations/chunker → lionagi-0.1.0/lionagi/core/mail}/__init__.py +0 -0
- {lionagi-0.0.315/lionagi/integrations/loader → lionagi-0.1.0/lionagi/core/messages}/__init__.py +0 -0
- {lionagi-0.0.315/lionagi/tests → lionagi-0.1.0/lionagi/core/session}/__init__.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/__init__.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/bridge/__init__.py +0 -0
- {lionagi-0.0.315/lionagi/tests/test_core → lionagi-0.1.0/lionagi/integrations/bridge/langchain_}/__init__.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/bridge/langchain_/documents.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/bridge/langchain_/langchain_bridge.py +0 -0
- {lionagi-0.0.315/lionagi/tests/test_integrations → lionagi-0.1.0/lionagi/integrations/bridge/llamaindex_}/__init__.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/bridge/llamaindex_/index.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/bridge/llamaindex_/node_parser.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/bridge/llamaindex_/reader.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/bridge/llamaindex_/textnode.py +0 -0
- {lionagi-0.0.315/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/integrations/bridge/pydantic_}/__init__.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +0 -0
- /lionagi-0.0.315/lionagi/tests/test_libs/test_async.py → /lionagi-0.1.0/lionagi/integrations/chunker/__init__.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/config/__init__.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/config/mlx_configs.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/config/ollama_configs.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/config/openrouter_configs.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/provider/__init__.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/provider/litellm.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/provider/mistralai.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/provider/mlx_service.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/provider/oai.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/provider/ollama.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/provider/openrouter.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/provider/services.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/integrations/provider/transformers.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/libs/__init__.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/libs/ln_async.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/libs/ln_convert.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/libs/ln_dataframe.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/libs/ln_func_call.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/libs/ln_nested.py +0 -0
- {lionagi-0.0.315/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_api.py +0 -0
- {lionagi-0.0.315/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_convert.py +0 -0
- {lionagi-0.0.315/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_func_call.py +0 -0
- {lionagi-0.0.315/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_nested.py +0 -0
- {lionagi-0.0.315/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_parse.py +0 -0
- {lionagi-0.0.315/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_sys_util.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/tests/test_core/test_chat_flow.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/tests/test_core/test_mail_manager.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/tests/test_core/test_prompts.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/tests/test_core/test_session.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi/tests/test_core/test_tool_manager.py +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi.egg-info/dependency_links.txt +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi.egg-info/requires.txt +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/lionagi.egg-info/top_level.txt +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/pyproject.toml +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/setup.cfg +0 -0
- {lionagi-0.0.315 → lionagi-0.1.0}/setup.py +0 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
from . import *
|
2
|
+
|
3
|
+
from .branch.branch import Branch
|
4
|
+
from .session.session import Session
|
5
|
+
from .generic import (
|
6
|
+
ActionNode,
|
7
|
+
ActionSelection,
|
8
|
+
Condition,
|
9
|
+
)
|
10
|
+
from .agent.base_agent import BaseAgent
|
11
|
+
from .messages.schema import Instruction, System, Response
|
12
|
+
from .tool import func_to_tool
|
13
|
+
|
14
|
+
|
15
|
+
__all__ = [
|
16
|
+
"ActionNode",
|
17
|
+
"ActionSelection",
|
18
|
+
"Branch",
|
19
|
+
"Condition",
|
20
|
+
"Session",
|
21
|
+
"System",
|
22
|
+
"Instruction",
|
23
|
+
"Response",
|
24
|
+
"BaseAgent",
|
25
|
+
"func_to_tool",
|
26
|
+
]
|
@@ -2,37 +2,28 @@
|
|
2
2
|
This module contains the BaseAgent class, which serves as a base class for agents.
|
3
3
|
"""
|
4
4
|
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from lionagi.core.mail.mail_manager import MailManager
|
5
|
+
from pydantic import Field
|
6
|
+
from typing import Any, Callable
|
8
7
|
|
9
8
|
from lionagi.libs import func_call, AsyncUtil
|
10
9
|
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
structure: The structure of the agent.
|
18
|
-
executable: The executable object of the agent.
|
19
|
-
start: The StartMail object for triggering the agent.
|
20
|
-
mailManager: The MailManager object for managing agent communication.
|
21
|
-
output_parser: A function for parsing the agent's output (optional).
|
22
|
-
start_context: The initial context for the agent (optional).
|
23
|
-
|
24
|
-
Methods:
|
25
|
-
__init__(self, structure, executable_obj, output_parser=None) -> None:
|
26
|
-
Initializes the BaseAgent instance.
|
11
|
+
from lionagi.core.mail.schema import StartMail
|
12
|
+
from lionagi.core.generic import Node
|
13
|
+
from lionagi.core.mail.mail_manager import MailManager
|
14
|
+
from lionagi.core.execute.base_executor import BaseExecutor
|
15
|
+
from lionagi.core.execute.structure_executor import StructureExecutor
|
27
16
|
|
28
|
-
async mail_manager_control(self, refresh_time=1) -> None:
|
29
|
-
Controls the mail manager execution based on the structure and executable states.
|
30
17
|
|
31
|
-
|
32
|
-
Executes the agent with the given context and returns the parsed output (if available).
|
33
|
-
"""
|
18
|
+
class BaseAgent(Node):
|
34
19
|
|
35
|
-
def __init__(
|
20
|
+
def __init__(
|
21
|
+
self,
|
22
|
+
structure: StructureExecutor,
|
23
|
+
executable: BaseExecutor,
|
24
|
+
output_parser=None,
|
25
|
+
**kwargs,
|
26
|
+
) -> None:
|
36
27
|
"""
|
37
28
|
Initializes the BaseAgent instance.
|
38
29
|
|
@@ -42,12 +33,16 @@ class BaseAgent(BaseRelatableNode):
|
|
42
33
|
output_parser: A function for parsing the agent's output (optional).
|
43
34
|
"""
|
44
35
|
super().__init__()
|
45
|
-
self.structure = structure
|
46
|
-
self.executable =
|
47
|
-
|
48
|
-
|
49
|
-
self.
|
50
|
-
self.
|
36
|
+
self.structure: StructureExecutor = structure
|
37
|
+
self.executable: BaseExecutor = executable
|
38
|
+
for v, k in kwargs.items():
|
39
|
+
executable.__setattr__(v, k)
|
40
|
+
self.start: StartMail = StartMail()
|
41
|
+
self.mailManager: MailManager = MailManager(
|
42
|
+
[self.structure, self.executable, self.start]
|
43
|
+
)
|
44
|
+
self.output_parser: Callable | None = output_parser
|
45
|
+
self.start_context: Any | None = None
|
51
46
|
|
52
47
|
async def mail_manager_control(self, refresh_time=1):
|
53
48
|
"""
|
@@ -92,3 +87,4 @@ class BaseAgent(BaseRelatableNode):
|
|
92
87
|
|
93
88
|
if self.output_parser:
|
94
89
|
return self.output_parser(self)
|
90
|
+
|
lionagi-0.0.315/lionagi/core/branch/base_branch.py → lionagi-0.1.0/lionagi/core/branch/base.py
RENAMED
@@ -1,22 +1,21 @@
|
|
1
1
|
from abc import ABC
|
2
2
|
from typing import Any
|
3
3
|
|
4
|
-
from
|
4
|
+
from pathlib import Path
|
5
5
|
from lionagi.libs import convert, dataframe, SysUtil
|
6
6
|
|
7
|
-
from
|
8
|
-
from
|
9
|
-
from ..messages.schema import (
|
7
|
+
from lionagi.core.generic import BaseNode, DataLogger, DLog
|
8
|
+
from lionagi.core.messages.schema import (
|
10
9
|
BranchColumns,
|
11
10
|
System,
|
12
11
|
Response,
|
13
12
|
Instruction,
|
14
13
|
BaseMessage,
|
15
14
|
)
|
16
|
-
from .util import MessageUtil
|
15
|
+
from lionagi.core.branch.util import MessageUtil
|
17
16
|
|
18
17
|
|
19
|
-
class BaseBranch(
|
18
|
+
class BaseBranch(BaseNode, ABC):
|
20
19
|
"""
|
21
20
|
Base class for managing branches of conversation, incorporating messages
|
22
21
|
and logging functionality.
|
@@ -24,7 +23,7 @@ class BaseBranch(BaseRelatableNode, ABC):
|
|
24
23
|
Attributes:
|
25
24
|
messages (dataframe.ln_DataFrame): Holds the messages in the branch.
|
26
25
|
datalogger (DataLogger): Logs data related to the branch's operation.
|
27
|
-
persist_path (
|
26
|
+
persist_path (str | Path): Filesystem path for data persistence.
|
28
27
|
"""
|
29
28
|
|
30
29
|
_columns: list[str] = BranchColumns.COLUMNS.value
|
@@ -33,7 +32,7 @@ class BaseBranch(BaseRelatableNode, ABC):
|
|
33
32
|
self,
|
34
33
|
messages: dataframe.ln_DataFrame | None = None,
|
35
34
|
datalogger: DataLogger | None = None,
|
36
|
-
persist_path:
|
35
|
+
persist_path: str | Path | None = None,
|
37
36
|
name=None,
|
38
37
|
**kwargs,
|
39
38
|
) -> None:
|
@@ -97,6 +96,7 @@ class BaseBranch(BaseRelatableNode, ABC):
|
|
97
96
|
if self.name is not None:
|
98
97
|
_msg.sender = self.name
|
99
98
|
|
99
|
+
setattr(_msg, "node_id", _msg.id_)
|
100
100
|
_msg.content = _msg.msg_content
|
101
101
|
self.messages.loc[len(self.messages)] = _msg.to_pd_series()
|
102
102
|
|
@@ -332,7 +332,7 @@ class BaseBranch(BaseRelatableNode, ABC):
|
|
332
332
|
|
333
333
|
def to_csv_file(
|
334
334
|
self,
|
335
|
-
filename:
|
335
|
+
filename: str | Path = "messages.csv",
|
336
336
|
dir_exist_ok: bool = True,
|
337
337
|
timestamp: bool = True,
|
338
338
|
time_prefix: bool = False,
|
@@ -375,7 +375,7 @@ class BaseBranch(BaseRelatableNode, ABC):
|
|
375
375
|
|
376
376
|
def to_json_file(
|
377
377
|
self,
|
378
|
-
filename:
|
378
|
+
filename: str | Path = "messages.json",
|
379
379
|
dir_exist_ok: bool = True,
|
380
380
|
timestamp: bool = True,
|
381
381
|
time_prefix: bool = False,
|
@@ -420,7 +420,7 @@ class BaseBranch(BaseRelatableNode, ABC):
|
|
420
420
|
|
421
421
|
def log_to_csv(
|
422
422
|
self,
|
423
|
-
filename:
|
423
|
+
filename: str | Path = "log.csv",
|
424
424
|
dir_exist_ok: bool = True,
|
425
425
|
timestamp: bool = True,
|
426
426
|
time_prefix: bool = False,
|
@@ -456,7 +456,7 @@ class BaseBranch(BaseRelatableNode, ABC):
|
|
456
456
|
|
457
457
|
def log_to_json(
|
458
458
|
self,
|
459
|
-
filename:
|
459
|
+
filename: str | Path = "log.json",
|
460
460
|
dir_exist_ok: bool = True,
|
461
461
|
timestamp: bool = True,
|
462
462
|
time_prefix: bool = False,
|
@@ -636,7 +636,6 @@ class BaseBranch(BaseRelatableNode, ABC):
|
|
636
636
|
case_sensitive=case_sensitive,
|
637
637
|
)
|
638
638
|
|
639
|
-
# noinspection PyTestUnpassedFixture
|
640
639
|
def _info(self, use_sender: bool = False) -> dict[str, int]:
|
641
640
|
"""
|
642
641
|
Helper method to generate summaries of messages either by role or sender.
|
@@ -651,4 +650,4 @@ class BaseBranch(BaseRelatableNode, ABC):
|
|
651
650
|
messages = self.messages["sender"] if use_sender else self.messages["role"]
|
652
651
|
result = messages.value_counts().to_dict()
|
653
652
|
result["total"] = len(self.messages)
|
654
|
-
return result
|
653
|
+
return result
|
@@ -4,19 +4,18 @@ This module contains the Branch class, which represents a branch in a conversati
|
|
4
4
|
|
5
5
|
from collections import deque
|
6
6
|
from typing import Any, Union, TypeVar, Callable
|
7
|
+
from pathlib import Path
|
7
8
|
|
8
|
-
from lionagi.libs.sys_util import PATH_TYPE
|
9
9
|
from lionagi.libs import StatusTracker, BaseService, convert, dataframe
|
10
10
|
|
11
|
-
from
|
12
|
-
from
|
11
|
+
from lionagi.core.generic import DataLogger
|
12
|
+
from lionagi.core.tool import ToolManager, func_to_tool, Tool, TOOL_TYPE
|
13
|
+
from lionagi.core.messages.schema import System
|
14
|
+
from lionagi.core.mail.schema import BaseMail
|
13
15
|
|
14
|
-
from
|
15
|
-
from
|
16
|
-
|
17
|
-
from .util import MessageUtil
|
18
|
-
from .base_branch import BaseBranch
|
19
|
-
from .branch_flow_mixin import BranchFlowMixin
|
16
|
+
from lionagi.core.branch.util import MessageUtil
|
17
|
+
from lionagi.core.branch.base import BaseBranch
|
18
|
+
from lionagi.core.branch.flow_mixin import BranchFlowMixin
|
20
19
|
|
21
20
|
from dotenv import load_dotenv
|
22
21
|
|
@@ -95,7 +94,7 @@ class Branch(BaseBranch, BranchFlowMixin):
|
|
95
94
|
llmconfig: dict[str, str | int | dict] | None = None,
|
96
95
|
tools: list[Callable | Tool] | None = None,
|
97
96
|
datalogger: None | DataLogger = None,
|
98
|
-
persist_path:
|
97
|
+
persist_path: str | Path | None = None, # instruction_sets=None,
|
99
98
|
tool_manager: ToolManager | None = None,
|
100
99
|
**kwargs,
|
101
100
|
):
|
@@ -111,7 +110,7 @@ class Branch(BaseBranch, BranchFlowMixin):
|
|
111
110
|
llmconfig (dict[str, str | int | dict]): The configuration for the language model (optional).
|
112
111
|
tools (list[Callable | Tool]): The tools to register in the branch (optional).
|
113
112
|
datalogger (DataLogger): The data logger for the branch (optional).
|
114
|
-
persist_path (
|
113
|
+
persist_path (str | Path): The path to persist the branch data (optional).
|
115
114
|
tool_manager (ToolManager): The tool manager for the branch (optional).
|
116
115
|
**kwargs: Additional keyword arguments.
|
117
116
|
|
@@ -165,7 +164,7 @@ class Branch(BaseBranch, BranchFlowMixin):
|
|
165
164
|
llmconfig: dict[str, str | int | dict] | None = None,
|
166
165
|
tools: TOOL_TYPE | None = None,
|
167
166
|
datalogger: None | DataLogger = None,
|
168
|
-
persist_path:
|
167
|
+
persist_path: str | Path | None = None, # instruction_sets=None,
|
169
168
|
tool_manager: ToolManager | None = None,
|
170
169
|
read_kwargs=None,
|
171
170
|
**kwargs,
|
@@ -180,7 +179,7 @@ class Branch(BaseBranch, BranchFlowMixin):
|
|
180
179
|
llmconfig (dict[str, str | int | dict]): The configuration for the language model (optional).
|
181
180
|
tools (TOOL_TYPE): The tools to register in the branch (optional).
|
182
181
|
datalogger (DataLogger): The data logger for the branch (optional).
|
183
|
-
persist_path (
|
182
|
+
persist_path (str | Path): The path to persist the branch data (optional).
|
184
183
|
tool_manager (ToolManager): The tool manager for the branch (optional).
|
185
184
|
read_kwargs: Additional keyword arguments for reading the CSV file (optional).
|
186
185
|
**kwargs: Additional keyword arguments.
|
@@ -211,7 +210,7 @@ class Branch(BaseBranch, BranchFlowMixin):
|
|
211
210
|
llmconfig: dict[str, str | int | dict] | None = None,
|
212
211
|
tools: TOOL_TYPE | None = None,
|
213
212
|
datalogger: None | DataLogger = None,
|
214
|
-
persist_path:
|
213
|
+
persist_path: str | Path | None = None, # instruction_sets=None,
|
215
214
|
tool_manager: ToolManager | None = None,
|
216
215
|
read_kwargs=None,
|
217
216
|
**kwargs,
|
@@ -226,7 +225,7 @@ class Branch(BaseBranch, BranchFlowMixin):
|
|
226
225
|
llmconfig (dict[str, str | int | dict]): The configuration for the language model (optional).
|
227
226
|
tools (TOOL_TYPE): The tools to register in the branch (optional).
|
228
227
|
datalogger (DataLogger): The data logger for the branch (optional).
|
229
|
-
persist_path (
|
228
|
+
persist_path (str | Path): The path to persist the branch data (optional).
|
230
229
|
tool_manager (ToolManager): The tool manager for the branch (optional).
|
231
230
|
read_kwargs: Additional keyword arguments for reading the JSON string file (optional).
|
232
231
|
**kwargs: Additional keyword arguments.
|
@@ -348,7 +347,7 @@ class Branch(BaseBranch, BranchFlowMixin):
|
|
348
347
|
print("tools deletion failed")
|
349
348
|
return False
|
350
349
|
|
351
|
-
def send(self,
|
350
|
+
def send(self, recipient_id: str, category: str, package: Any) -> None:
|
352
351
|
"""
|
353
352
|
Sends a mail to a recipient.
|
354
353
|
|
@@ -357,10 +356,13 @@ class Branch(BaseBranch, BranchFlowMixin):
|
|
357
356
|
category (str): The category of the mail.
|
358
357
|
package (Any): The package to send in the mail.
|
359
358
|
"""
|
360
|
-
|
361
|
-
|
359
|
+
mail = BaseMail(
|
360
|
+
sender_id=self.id_,
|
361
|
+
recipient_id=recipient_id,
|
362
|
+
category=category,
|
363
|
+
package=package,
|
362
364
|
)
|
363
|
-
self.pending_outs.append(
|
365
|
+
self.pending_outs.append(mail)
|
364
366
|
|
365
367
|
def receive(
|
366
368
|
self,
|
@@ -468,4 +470,4 @@ class Branch(BaseBranch, BranchFlowMixin):
|
|
468
470
|
}:
|
469
471
|
return True
|
470
472
|
except Exception:
|
471
|
-
return False
|
473
|
+
return False
|
@@ -1,9 +1,9 @@
|
|
1
1
|
from abc import ABC
|
2
2
|
from typing import Any, Optional, Union, TypeVar
|
3
3
|
|
4
|
-
from
|
5
|
-
from
|
6
|
-
from
|
4
|
+
from lionagi.core.tool import Tool, TOOL_TYPE
|
5
|
+
from lionagi.core.messages.schema import Instruction, System
|
6
|
+
from lionagi.core.flow.monoflow import MonoChat, MonoFollowup, MonoReAct
|
7
7
|
|
8
8
|
T = TypeVar("T", bound=Tool)
|
9
9
|
|
@@ -20,7 +20,7 @@ class BranchFlowMixin(ABC):
|
|
20
20
|
out: bool = True,
|
21
21
|
invoke: bool = True,
|
22
22
|
output_fields=None,
|
23
|
-
|
23
|
+
form=None,
|
24
24
|
**kwargs,
|
25
25
|
) -> Any:
|
26
26
|
flow = MonoChat(self)
|
@@ -33,7 +33,7 @@ class BranchFlowMixin(ABC):
|
|
33
33
|
out=out,
|
34
34
|
invoke=invoke,
|
35
35
|
output_fields=output_fields,
|
36
|
-
|
36
|
+
form=form,
|
37
37
|
**kwargs,
|
38
38
|
)
|
39
39
|
|
@@ -93,4 +93,4 @@ class BranchFlowMixin(ABC):
|
|
93
93
|
output_prompt=output_prompt,
|
94
94
|
out=out,
|
95
95
|
**kwargs,
|
96
|
-
)
|
96
|
+
)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from .predict import predict
|
2
|
+
from .select import select
|
3
|
+
from .score import score
|
4
|
+
from .react import react
|
5
|
+
from .vote import vote
|
6
|
+
from .plan import plan
|
7
|
+
from .cot import chain_of_thoughts, chain_of_react
|
8
|
+
|
9
|
+
|
10
|
+
__all__ = [
|
11
|
+
"predict",
|
12
|
+
"select",
|
13
|
+
"score",
|
14
|
+
"vote",
|
15
|
+
"react",
|
16
|
+
"plan",
|
17
|
+
"chain_of_thoughts",
|
18
|
+
"chain_of_react",
|
19
|
+
]
|
@@ -0,0 +1,123 @@
|
|
1
|
+
from lionagi.libs import convert
|
2
|
+
|
3
|
+
from lionagi.core.direct.predict import predict
|
4
|
+
from lionagi.core.direct.plan import plan
|
5
|
+
from lionagi.core.direct.react import react
|
6
|
+
|
7
|
+
from .utils import _process_tools
|
8
|
+
|
9
|
+
|
10
|
+
async def chain_of_thoughts(
|
11
|
+
sentence=None,
|
12
|
+
branch=None,
|
13
|
+
instruction=None,
|
14
|
+
reason=False,
|
15
|
+
confidence_score=False,
|
16
|
+
num_steps=3,
|
17
|
+
directive_kwargs={},
|
18
|
+
return_branch=False,
|
19
|
+
**kwargs,
|
20
|
+
):
|
21
|
+
|
22
|
+
out_, outs, answer, reasons, confidence_score = "", [], "", [], 0
|
23
|
+
if branch is not None:
|
24
|
+
out_ = await plan(
|
25
|
+
sentence,
|
26
|
+
branch=branch,
|
27
|
+
instruction=instruction,
|
28
|
+
num_steps=num_steps,
|
29
|
+
**kwargs,
|
30
|
+
)
|
31
|
+
else:
|
32
|
+
out_, branch = await plan(
|
33
|
+
sentence,
|
34
|
+
instruction=instruction,
|
35
|
+
branch=branch,
|
36
|
+
num_steps=num_steps,
|
37
|
+
return_branch=True,
|
38
|
+
**kwargs,
|
39
|
+
)
|
40
|
+
|
41
|
+
for i in range(len(out_.plan)):
|
42
|
+
_out = await predict(
|
43
|
+
branch=branch,
|
44
|
+
instruction=out_.plan[f"step_{i+1}"],
|
45
|
+
reason=reason,
|
46
|
+
confidence_score=confidence_score,
|
47
|
+
**directive_kwargs,
|
48
|
+
)
|
49
|
+
answer += _out.answer
|
50
|
+
if reason:
|
51
|
+
reasons.append(_out.reason)
|
52
|
+
if confidence_score:
|
53
|
+
confidence_score += _out.confidence_score
|
54
|
+
outs.append(_out)
|
55
|
+
|
56
|
+
setattr(out_, "chain_output", outs)
|
57
|
+
setattr(out_, "chain_answer", answer)
|
58
|
+
|
59
|
+
if reason:
|
60
|
+
setattr(out_, "chain_reasons", reasons)
|
61
|
+
if confidence_score:
|
62
|
+
setattr(out_, "chain_confidence_score", confidence_score / len(outs))
|
63
|
+
|
64
|
+
if return_branch:
|
65
|
+
return out_, branch
|
66
|
+
|
67
|
+
return out_
|
68
|
+
|
69
|
+
|
70
|
+
async def chain_of_react(
|
71
|
+
sentence=None,
|
72
|
+
branch=None,
|
73
|
+
instruction=None,
|
74
|
+
num_steps=3,
|
75
|
+
tools=None,
|
76
|
+
directive_system=None,
|
77
|
+
directive_kwargs={},
|
78
|
+
return_branch=False,
|
79
|
+
**kwargs,
|
80
|
+
):
|
81
|
+
out_, outs, reasons, actions, action_responses = "", [], [], [], []
|
82
|
+
if branch is not None:
|
83
|
+
out_ = await plan(
|
84
|
+
sentence,
|
85
|
+
branch=branch,
|
86
|
+
instruction=instruction,
|
87
|
+
num_steps=num_steps,
|
88
|
+
**kwargs,
|
89
|
+
)
|
90
|
+
else:
|
91
|
+
out_, branch = await plan(
|
92
|
+
sentence,
|
93
|
+
instruction=instruction,
|
94
|
+
branch=branch,
|
95
|
+
num_steps=num_steps,
|
96
|
+
return_branch=True,
|
97
|
+
**kwargs,
|
98
|
+
)
|
99
|
+
|
100
|
+
_process_tools(tools, branch)
|
101
|
+
|
102
|
+
for i in range(len(out_.plan)):
|
103
|
+
_out = await react(
|
104
|
+
branch=branch,
|
105
|
+
system=directive_system,
|
106
|
+
instruction=out_.plan[f"step_{i+1}"],
|
107
|
+
**directive_kwargs,
|
108
|
+
)
|
109
|
+
outs.append(_out)
|
110
|
+
reasons.append(_out.reason)
|
111
|
+
actions.append(_out.actions)
|
112
|
+
if _out.action_needed:
|
113
|
+
action_responses.append(_out.action_response)
|
114
|
+
|
115
|
+
setattr(out_, "chain_output", convert.to_list(outs))
|
116
|
+
setattr(out_, "chain_reason", convert.to_list(reasons))
|
117
|
+
setattr(out_, "chain_actions", convert.to_list(actions))
|
118
|
+
setattr(out_, "chain_action_response", convert.to_list(action_responses))
|
119
|
+
|
120
|
+
if return_branch:
|
121
|
+
return out_, branch
|
122
|
+
|
123
|
+
return out_
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# plan.py
|
2
|
+
|
3
|
+
from lionagi.libs import func_call, ParseUtil
|
4
|
+
from lionagi.integrations.bridge.pydantic_.pydantic_bridge import Field
|
5
|
+
from lionagi.core.form.scored_form import ScoredForm
|
6
|
+
from lionagi.core.branch.branch import Branch
|
7
|
+
|
8
|
+
|
9
|
+
class PlanTemplate(ScoredForm):
|
10
|
+
template_name: str = "default_plan"
|
11
|
+
sentence: str | list | dict = Field(
|
12
|
+
default_factory=str,
|
13
|
+
description="the given sentence(s) or context to generate a plan for",
|
14
|
+
)
|
15
|
+
plan: dict | str = Field(
|
16
|
+
default_factory=dict,
|
17
|
+
description="the generated step by step plan, return as a dictionary following {step_n: {plan: ..., reason: ...}} format",
|
18
|
+
)
|
19
|
+
signature: str = "sentence -> plan"
|
20
|
+
|
21
|
+
def __init__(
|
22
|
+
self,
|
23
|
+
sentence=None,
|
24
|
+
instruction=None,
|
25
|
+
confidence_score=False,
|
26
|
+
reason=False,
|
27
|
+
num_step=3,
|
28
|
+
**kwargs,
|
29
|
+
):
|
30
|
+
super().__init__(**kwargs)
|
31
|
+
|
32
|
+
self.sentence = sentence
|
33
|
+
self.task = f"Generate a {num_step}_step plan based on the given context. Instruction: {instruction}."
|
34
|
+
|
35
|
+
if reason:
|
36
|
+
self.output_fields.append("reason")
|
37
|
+
|
38
|
+
if confidence_score:
|
39
|
+
self.output_fields.append("confidence_score")
|
40
|
+
|
41
|
+
|
42
|
+
async def _plan(
|
43
|
+
sentence,
|
44
|
+
*,
|
45
|
+
instruction=None,
|
46
|
+
branch=None,
|
47
|
+
confidence_score=False,
|
48
|
+
reason=False,
|
49
|
+
retries=2,
|
50
|
+
delay=0.5,
|
51
|
+
backoff_factor=2,
|
52
|
+
default_value=None,
|
53
|
+
timeout=None,
|
54
|
+
branch_name=None,
|
55
|
+
system=None,
|
56
|
+
messages=None,
|
57
|
+
service=None,
|
58
|
+
sender=None,
|
59
|
+
llmconfig=None,
|
60
|
+
tools=None,
|
61
|
+
datalogger=None,
|
62
|
+
persist_path=None,
|
63
|
+
tool_manager=None,
|
64
|
+
return_branch=False,
|
65
|
+
**kwargs,
|
66
|
+
):
|
67
|
+
if "temperature" not in kwargs:
|
68
|
+
kwargs["temperature"] = 0.1
|
69
|
+
|
70
|
+
instruction = instruction or ""
|
71
|
+
|
72
|
+
branch = branch or Branch(
|
73
|
+
name=branch_name,
|
74
|
+
system=system,
|
75
|
+
messages=messages,
|
76
|
+
service=service,
|
77
|
+
sender=sender,
|
78
|
+
llmconfig=llmconfig,
|
79
|
+
tools=tools,
|
80
|
+
datalogger=datalogger,
|
81
|
+
persist_path=persist_path,
|
82
|
+
tool_manager=tool_manager,
|
83
|
+
)
|
84
|
+
|
85
|
+
_template = PlanTemplate(
|
86
|
+
sentence=sentence,
|
87
|
+
instruction=instruction,
|
88
|
+
confidence_score=confidence_score,
|
89
|
+
reason=reason,
|
90
|
+
)
|
91
|
+
|
92
|
+
await func_call.rcall(
|
93
|
+
branch.chat,
|
94
|
+
form=_template,
|
95
|
+
retries=retries,
|
96
|
+
delay=delay,
|
97
|
+
backoff_factor=backoff_factor,
|
98
|
+
default=default_value,
|
99
|
+
timeout=timeout,
|
100
|
+
**kwargs,
|
101
|
+
)
|
102
|
+
|
103
|
+
_template.plan = ParseUtil.fuzzy_parse_json(_template.plan)
|
104
|
+
|
105
|
+
return (_template, branch) if return_branch else _template
|
106
|
+
|
107
|
+
|
108
|
+
async def plan(
|
109
|
+
sentence,
|
110
|
+
*,
|
111
|
+
instruction=None,
|
112
|
+
num_instances=1,
|
113
|
+
branch=None,
|
114
|
+
confidence_score=False,
|
115
|
+
reason=False,
|
116
|
+
retries=2,
|
117
|
+
delay=0.5,
|
118
|
+
backoff_factor=2,
|
119
|
+
default_value=None,
|
120
|
+
timeout=None,
|
121
|
+
branch_name=None,
|
122
|
+
system=None,
|
123
|
+
messages=None,
|
124
|
+
service=None,
|
125
|
+
sender=None,
|
126
|
+
llmconfig=None,
|
127
|
+
tools=None,
|
128
|
+
datalogger=None,
|
129
|
+
persist_path=None,
|
130
|
+
tool_manager=None,
|
131
|
+
return_branch=False,
|
132
|
+
**kwargs,
|
133
|
+
):
|
134
|
+
async def _inner(i=0):
|
135
|
+
return await _plan(
|
136
|
+
sentence=sentence,
|
137
|
+
instruction=instruction,
|
138
|
+
branch=branch,
|
139
|
+
confidence_score=confidence_score,
|
140
|
+
reason=reason,
|
141
|
+
retries=retries,
|
142
|
+
delay=delay,
|
143
|
+
backoff_factor=backoff_factor,
|
144
|
+
default_value=default_value,
|
145
|
+
timeout=timeout,
|
146
|
+
branch_name=branch_name,
|
147
|
+
system=system,
|
148
|
+
messages=messages,
|
149
|
+
service=service,
|
150
|
+
sender=sender,
|
151
|
+
llmconfig=llmconfig,
|
152
|
+
tools=tools,
|
153
|
+
datalogger=datalogger,
|
154
|
+
persist_path=persist_path,
|
155
|
+
tool_manager=tool_manager,
|
156
|
+
return_branch=return_branch,
|
157
|
+
**kwargs,
|
158
|
+
)
|
159
|
+
|
160
|
+
if num_instances == 1:
|
161
|
+
return await _inner()
|
162
|
+
|
163
|
+
elif num_instances > 1:
|
164
|
+
return await func_call.alcall(range(num_instances), _inner)
|