lionagi 0.9.19__py3-none-any.whl → 0.10.0__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.
- lionagi/__init__.py +0 -7
- lionagi/_types.py +0 -1
- lionagi/libs/fields/__init__.py +36 -0
- lionagi/libs/fields/action.py +190 -0
- lionagi/libs/fields/file.py +135 -0
- lionagi/{operatives/instruct → libs/fields}/instruct.py +9 -9
- lionagi/{operatives/instruct → libs/fields}/reason.py +28 -49
- lionagi/libs/schema/function_to_schema.py +1 -1
- lionagi/models/__init__.py +19 -0
- lionagi/models/hashable_model.py +24 -0
- lionagi/{operatives/models → models}/operable_model.py +2 -1
- lionagi/{operatives/models → models}/schema_model.py +1 -1
- lionagi/operations/ReAct/ReAct.py +2 -3
- lionagi/operations/_act/act.py +2 -7
- lionagi/operations/brainstorm/brainstorm.py +1 -1
- lionagi/operations/instruct/instruct.py +1 -1
- lionagi/operations/operate/operate.py +6 -5
- lionagi/operations/parse/parse.py +1 -1
- lionagi/operations/plan/plan.py +1 -1
- lionagi/operations/select/select.py +1 -1
- lionagi/operations/utils.py +1 -1
- lionagi/{operatives → protocols}/action/function_calling.py +4 -1
- lionagi/{operatives → protocols}/action/manager.py +2 -9
- lionagi/{operatives → protocols}/action/tool.py +1 -6
- lionagi/{operatives → protocols}/forms/base.py +8 -2
- lionagi/{operatives → protocols}/forms/flow.py +6 -1
- lionagi/{operatives → protocols}/forms/form.py +6 -1
- lionagi/{operatives → protocols}/forms/report.py +7 -3
- lionagi/protocols/generic/pile.py +9 -5
- lionagi/protocols/graph/node.py +8 -4
- lionagi/protocols/mail/exchange.py +0 -6
- lionagi/protocols/mail/mail.py +0 -6
- lionagi/protocols/mail/mailbox.py +0 -5
- lionagi/protocols/mail/manager.py +0 -5
- lionagi/protocols/mail/package.py +0 -6
- lionagi/protocols/messages/action_request.py +0 -6
- lionagi/protocols/messages/action_response.py +0 -5
- lionagi/protocols/messages/assistant_response.py +0 -4
- lionagi/protocols/messages/base.py +0 -6
- lionagi/protocols/messages/instruction.py +0 -5
- lionagi/protocols/messages/manager.py +0 -6
- lionagi/protocols/messages/message.py +0 -5
- lionagi/protocols/messages/system.py +0 -5
- lionagi/{operatives → protocols/operatives}/operative.py +1 -3
- lionagi/{operatives → protocols/operatives}/step.py +5 -7
- lionagi/protocols/types.py +36 -21
- lionagi/service/endpoints/base.py +1 -1
- lionagi/service/endpoints/rate_limited_processor.py +1 -1
- lionagi/service/providers/ollama_/chat_completions.py +2 -2
- lionagi/session/branch.py +9 -10
- lionagi/session/session.py +24 -8
- lionagi/tools/base.py +1 -1
- lionagi/tools/file/reader.py +1 -1
- lionagi/utils.py +0 -22
- lionagi/version.py +1 -1
- {lionagi-0.9.19.dist-info → lionagi-0.10.0.dist-info}/METADATA +1 -1
- {lionagi-0.9.19.dist-info → lionagi-0.10.0.dist-info}/RECORD +75 -90
- lionagi/operatives/action/request_response_model.py +0 -121
- lionagi/operatives/action/utils.py +0 -147
- lionagi/operatives/instruct/__init__.py +0 -3
- lionagi/operatives/instruct/base.py +0 -81
- lionagi/operatives/instruct/instruct_collection.py +0 -52
- lionagi/operatives/instruct/node.py +0 -13
- lionagi/operatives/instruct/prompts.py +0 -51
- lionagi/operatives/manager.py +0 -9
- lionagi/operatives/models/__init__.py +0 -3
- lionagi/operatives/strategies/__init__.py +0 -3
- lionagi/operatives/strategies/base.py +0 -56
- lionagi/operatives/strategies/concurrent.py +0 -75
- lionagi/operatives/strategies/concurrent_chunk.py +0 -46
- lionagi/operatives/strategies/concurrent_sequential_chunk.py +0 -108
- lionagi/operatives/strategies/params.py +0 -151
- lionagi/operatives/strategies/sequential.py +0 -27
- lionagi/operatives/strategies/sequential_chunk.py +0 -93
- lionagi/operatives/strategies/sequential_concurrent_chunk.py +0 -105
- lionagi/operatives/strategies/utils.py +0 -52
- lionagi/operatives/types.py +0 -72
- /lionagi/{protocols/adapters → adapters}/__init__.py +0 -0
- /lionagi/{protocols/adapters → adapters}/adapter.py +0 -0
- /lionagi/{protocols/adapters → adapters}/json_adapter.py +0 -0
- /lionagi/{protocols/adapters → adapters}/pandas_/__init__.py +0 -0
- /lionagi/{protocols/adapters → adapters}/pandas_/csv_adapter.py +0 -0
- /lionagi/{protocols/adapters → adapters}/pandas_/excel_adapter.py +0 -0
- /lionagi/{protocols/adapters → adapters}/pandas_/pd_dataframe_adapter.py +0 -0
- /lionagi/{protocols/adapters → adapters}/pandas_/pd_series_adapter.py +0 -0
- /lionagi/{protocols/adapters → adapters}/toml_adapter.py +0 -0
- /lionagi/{protocols/adapters → adapters}/types.py +0 -0
- /lionagi/{operatives/models → models}/field_model.py +0 -0
- /lionagi/{operatives/models → models}/model_params.py +0 -0
- /lionagi/{operatives/models → models}/note.py +0 -0
- /lionagi/{operatives → protocols/action}/__init__.py +0 -0
- /lionagi/{operatives/action → protocols/forms}/__init__.py +0 -0
- /lionagi/{operatives/forms → protocols/operatives}/__init__.py +0 -0
- {lionagi-0.9.19.dist-info → lionagi-0.10.0.dist-info}/WHEEL +0 -0
- {lionagi-0.9.19.dist-info → lionagi-0.10.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,151 +0,0 @@
|
|
1
|
-
# Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
-
#
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
4
|
-
|
5
|
-
from typing import Any, Literal
|
6
|
-
|
7
|
-
from pydantic import Field, field_validator, model_validator
|
8
|
-
|
9
|
-
from lionagi.operatives.instruct.instruct import (
|
10
|
-
LIST_INSTRUCT_FIELD_MODEL,
|
11
|
-
Instruct,
|
12
|
-
)
|
13
|
-
from lionagi.operatives.types import FieldModel, SchemaModel
|
14
|
-
from lionagi.session.session import Branch, Session
|
15
|
-
|
16
|
-
|
17
|
-
class RCallParams(SchemaModel):
|
18
|
-
"""Parameters for remote function calls."""
|
19
|
-
|
20
|
-
timeout: float = Field(
|
21
|
-
default=60, description="Timeout for remote function call"
|
22
|
-
)
|
23
|
-
max_retries: int = Field(
|
24
|
-
default=3, description="Maximum number of retries"
|
25
|
-
)
|
26
|
-
retry_delay: float = Field(
|
27
|
-
default=0.5, description="Delay between retries"
|
28
|
-
)
|
29
|
-
retry_backoff: float = Field(
|
30
|
-
default=2, description="Backoff factor for retry delay"
|
31
|
-
)
|
32
|
-
|
33
|
-
|
34
|
-
class StrategyParams(SchemaModel):
|
35
|
-
"""Base parameters for execution strategies."""
|
36
|
-
|
37
|
-
instruct: list[Instruct] | Instruct = Field(
|
38
|
-
..., description="Instructions to execute"
|
39
|
-
)
|
40
|
-
session: Session | None = Field(
|
41
|
-
default=None, description="Session for managing branches"
|
42
|
-
)
|
43
|
-
branch: Branch | str | None = Field(
|
44
|
-
default=None, description="Branch or branch reference for execution"
|
45
|
-
)
|
46
|
-
verbose: bool = Field(
|
47
|
-
default=True, description="Whether to print execution progress"
|
48
|
-
)
|
49
|
-
execute_kwargs: dict[str, Any] = Field(
|
50
|
-
default_factory=dict,
|
51
|
-
description="Additional keyword arguments for execution",
|
52
|
-
)
|
53
|
-
branch_kwargs: dict[str, Any] = Field(
|
54
|
-
default_factory=dict,
|
55
|
-
description="Keyword arguments for creating new branches",
|
56
|
-
)
|
57
|
-
auto_run: bool = False
|
58
|
-
auto_execute: bool = False
|
59
|
-
instruct_model_field: type[FieldModel] = LIST_INSTRUCT_FIELD_MODEL
|
60
|
-
|
61
|
-
@field_validator("branch_kwargs", mode="before")
|
62
|
-
def _validate_branch_kwargs(cls, v: Any) -> dict:
|
63
|
-
if v is None:
|
64
|
-
return {}
|
65
|
-
if hasattr(v, "to_dict"):
|
66
|
-
return v.to_dict()
|
67
|
-
if isinstance(v, dict):
|
68
|
-
return v
|
69
|
-
raise ValueError("branch_kwargs must be a dictionary or SchemaModel")
|
70
|
-
|
71
|
-
@field_validator("instruct", mode="before")
|
72
|
-
def validate_instructions(cls, v: Any) -> list[Instruct]:
|
73
|
-
"""Validate and convert instructions to list format."""
|
74
|
-
if isinstance(v, Instruct):
|
75
|
-
return [v]
|
76
|
-
if isinstance(v, (list, tuple)):
|
77
|
-
if not all(isinstance(i, Instruct) for i in v):
|
78
|
-
raise ValueError("All instructions must be Instruct instances")
|
79
|
-
return list(v)
|
80
|
-
raise ValueError("Instructions must be Instruct or list of Instruct")
|
81
|
-
|
82
|
-
@field_validator("branch", mode="before")
|
83
|
-
def validate_branch(cls, v: Any) -> Branch | str | None:
|
84
|
-
"""Validate branch reference."""
|
85
|
-
if v is None or isinstance(v, (Branch, str)):
|
86
|
-
return v
|
87
|
-
raise ValueError("Branch must be a Branch instance or branch ID")
|
88
|
-
|
89
|
-
@field_validator("session", mode="before")
|
90
|
-
def validate_session(cls, v: Any) -> Session | None:
|
91
|
-
"""Validate session reference."""
|
92
|
-
if v is None or isinstance(v, Session):
|
93
|
-
return v
|
94
|
-
raise ValueError("Session must be a Session instance")
|
95
|
-
|
96
|
-
@model_validator(mode="after")
|
97
|
-
def _validate_session_branch(self):
|
98
|
-
if self.session is None:
|
99
|
-
self.session = Session()
|
100
|
-
if self.branch is None:
|
101
|
-
self.branch = self.session.new_branch(**self.branch_kwargs)
|
102
|
-
elif isinstance(self.branch, Branch):
|
103
|
-
if self.branch not in self.session.branches:
|
104
|
-
self.session.branches.include(self.branch)
|
105
|
-
elif isinstance(self.branch, str):
|
106
|
-
if self.branch not in self.session.branches:
|
107
|
-
raise ValueError("Branch ID not found in session")
|
108
|
-
self.branch = self.session.branches[self.branch]
|
109
|
-
return self
|
110
|
-
|
111
|
-
|
112
|
-
class ChunkStrategyParams(StrategyParams):
|
113
|
-
"""Parameters for chunked execution strategies."""
|
114
|
-
|
115
|
-
chunk_size: int = Field(
|
116
|
-
default=5,
|
117
|
-
description="Number of instructions to process in each chunk",
|
118
|
-
gt=0,
|
119
|
-
)
|
120
|
-
rcall_params: RCallParams = Field(default_factory=RCallParams)
|
121
|
-
|
122
|
-
@field_validator("rcall_params", mode="before")
|
123
|
-
def validate_rcall_params(cls, v: dict) -> RCallParams:
|
124
|
-
return RCallParams(**v)
|
125
|
-
|
126
|
-
|
127
|
-
class HybridStrategyParams(ChunkStrategyParams):
|
128
|
-
"""Parameters for hybrid execution strategies."""
|
129
|
-
|
130
|
-
outer_mode: Literal["concurrent", "sequential"] = Field(
|
131
|
-
..., description="Execution mode for outer loop"
|
132
|
-
)
|
133
|
-
inner_mode: Literal["concurrent", "sequential"] = Field(
|
134
|
-
..., description="Execution mode for inner loop"
|
135
|
-
)
|
136
|
-
inner_chunk_size: int | None = Field(
|
137
|
-
default=None, description="Chunk size for inner loop execution", gt=0
|
138
|
-
)
|
139
|
-
inner_rcall_params: RCallParams = Field(default_factory=RCallParams)
|
140
|
-
|
141
|
-
@field_validator("inner_chunk_size", mode="before")
|
142
|
-
def validate_inner_chunk_size(cls, v: Any) -> int | None:
|
143
|
-
if v is None:
|
144
|
-
return None
|
145
|
-
if not isinstance(v, int) or v <= 0:
|
146
|
-
raise ValueError("inner_chunk_size must be a positive integer")
|
147
|
-
return v
|
148
|
-
|
149
|
-
@field_validator("inner_rcall_params", mode="before")
|
150
|
-
def validate_inner_rcall_params(cls, v: dict):
|
151
|
-
return RCallParams(**v)
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
-
#
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
4
|
-
|
5
|
-
from lionagi.operatives.instruct.instruct import Instruct, InstructResponse
|
6
|
-
|
7
|
-
from .base import StrategyExecutor
|
8
|
-
|
9
|
-
|
10
|
-
class SequentialExecutor(StrategyExecutor):
|
11
|
-
"""Executor that runs instructions sequentially, one after another."""
|
12
|
-
|
13
|
-
async def execute(
|
14
|
-
self, res
|
15
|
-
) -> tuple[list[Instruct], list[InstructResponse]]:
|
16
|
-
ress = []
|
17
|
-
instructs = (
|
18
|
-
res.instruct_models if hasattr(res, "instruct_models") else []
|
19
|
-
)
|
20
|
-
for idx, item in enumerate(instructs, start=1):
|
21
|
-
if self.params.verbose:
|
22
|
-
print(f"\nExecuting step {idx}/{len(instructs)}")
|
23
|
-
out = await self.execute_branch.instruct(
|
24
|
-
item, **self.params.execute_kwargs
|
25
|
-
)
|
26
|
-
ress.append(InstructResponse(instruct=item, response=out))
|
27
|
-
return instructs, ress
|
@@ -1,93 +0,0 @@
|
|
1
|
-
# Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
-
#
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
4
|
-
|
5
|
-
from pydantic import model_validator
|
6
|
-
|
7
|
-
from lionagi.operatives.instruct.instruct import Instruct, InstructResponse
|
8
|
-
from lionagi.session.session import Branch, Session
|
9
|
-
|
10
|
-
from .base import StrategyExecutor
|
11
|
-
from .params import ChunkStrategyParams
|
12
|
-
|
13
|
-
|
14
|
-
class SequentialChunkExecutor(StrategyExecutor):
|
15
|
-
"""Executor for sequential chunked instruction processing.
|
16
|
-
|
17
|
-
Splits instructions into chunks and processes each chunk one by one.
|
18
|
-
"""
|
19
|
-
|
20
|
-
params: ChunkStrategyParams
|
21
|
-
session: Session
|
22
|
-
branch: Branch
|
23
|
-
|
24
|
-
@model_validator(mode="before")
|
25
|
-
def validate_execution_config(cls, values: dict) -> dict:
|
26
|
-
params = values.get("params", None)
|
27
|
-
if params is None:
|
28
|
-
params = ChunkStrategyParams(**values)
|
29
|
-
|
30
|
-
session = values.get("session", params.session)
|
31
|
-
if not session:
|
32
|
-
raise ValueError(
|
33
|
-
"Session is required for sequential chunk execution"
|
34
|
-
)
|
35
|
-
|
36
|
-
branch = values.get("branch", params.branch)
|
37
|
-
if isinstance(branch, Branch):
|
38
|
-
if branch not in session.branches:
|
39
|
-
session.branches.include(branch)
|
40
|
-
elif not branch:
|
41
|
-
branch = session.new_branch()
|
42
|
-
elif isinstance(branch, str):
|
43
|
-
branch = session.split(branch)
|
44
|
-
else:
|
45
|
-
raise ValueError("Invalid branch type")
|
46
|
-
|
47
|
-
return {"params": params, "session": session, "branch": branch}
|
48
|
-
|
49
|
-
async def _execute_single(
|
50
|
-
self, ins_: Instruct, idx: int, ttl: int
|
51
|
-
) -> InstructResponse:
|
52
|
-
if self.params.verbose:
|
53
|
-
msg_ = (
|
54
|
-
(ins_.instruction[:100] + "...")
|
55
|
-
if len(ins_.instruction) > 100
|
56
|
-
else ins_.instruction
|
57
|
-
)
|
58
|
-
if idx and ttl:
|
59
|
-
print(f"\n-----Executing Instruct {idx}/{ttl}-----\n{msg_}")
|
60
|
-
else:
|
61
|
-
print(f"\n-----Executing Instruct-----\n{msg_}")
|
62
|
-
|
63
|
-
res = await self.branch.instruct(ins_, **self.params.execute_kwargs)
|
64
|
-
return InstructResponse(instruct=ins_, response=res)
|
65
|
-
|
66
|
-
async def _execute_chunk(
|
67
|
-
self, chunk: list[tuple[Instruct, int, int]]
|
68
|
-
) -> list[InstructResponse]:
|
69
|
-
responses = []
|
70
|
-
for ins_, idx, ttl in chunk:
|
71
|
-
res = await self._execute_single(ins_, idx, ttl)
|
72
|
-
responses.append(res)
|
73
|
-
return responses
|
74
|
-
|
75
|
-
async def execute(self) -> list[InstructResponse]:
|
76
|
-
instructions = self.params.instruct
|
77
|
-
chunk_size = self.params.chunk_size
|
78
|
-
total = len(instructions)
|
79
|
-
|
80
|
-
if total <= chunk_size:
|
81
|
-
chunk = [(ins, i + 1, total) for i, ins in enumerate(instructions)]
|
82
|
-
return await self._execute_chunk(chunk)
|
83
|
-
|
84
|
-
responses = []
|
85
|
-
for start in range(0, total, chunk_size):
|
86
|
-
end = min(start + chunk_size, total)
|
87
|
-
chunk = [
|
88
|
-
(instructions[i], i + 1, total) for i in range(start, end)
|
89
|
-
]
|
90
|
-
chunk_responses = await self._execute_chunk(chunk)
|
91
|
-
responses.extend(chunk_responses)
|
92
|
-
|
93
|
-
return responses
|
@@ -1,105 +0,0 @@
|
|
1
|
-
# Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
-
#
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
4
|
-
|
5
|
-
from pydantic import model_validator
|
6
|
-
|
7
|
-
from lionagi.operations.strategies.params import HybridStrategyParams
|
8
|
-
from lionagi.operatives.instruct.instruct import Instruct, InstructResponse
|
9
|
-
from lionagi.session.session import Branch, Session
|
10
|
-
from lionagi.utils import alcall
|
11
|
-
|
12
|
-
from .base import StrategyExecutor
|
13
|
-
from .params import HybridStrategyParams
|
14
|
-
|
15
|
-
|
16
|
-
class SequentialConcurrentChunkExecutor(StrategyExecutor):
|
17
|
-
"""Sequential-concurrent chunked executor:
|
18
|
-
1. Splits instructions into chunks
|
19
|
-
2. Processes chunks sequentially
|
20
|
-
3. Within each chunk, processes instructions concurrently
|
21
|
-
"""
|
22
|
-
|
23
|
-
params: HybridStrategyParams
|
24
|
-
session: Session
|
25
|
-
branch: Branch
|
26
|
-
|
27
|
-
@model_validator(mode="before")
|
28
|
-
def validate_execution_config(cls, values: dict) -> dict:
|
29
|
-
params = values.get("params", None)
|
30
|
-
if params is None:
|
31
|
-
params = HybridStrategyParams(**values)
|
32
|
-
|
33
|
-
if (
|
34
|
-
params.outer_mode != "sequential"
|
35
|
-
or params.inner_mode != "concurrent"
|
36
|
-
):
|
37
|
-
raise ValueError(
|
38
|
-
"Requires outer_mode='sequential' and inner_mode='concurrent'"
|
39
|
-
)
|
40
|
-
|
41
|
-
session = values.get("session", params.session)
|
42
|
-
if not session:
|
43
|
-
raise ValueError("Session is required")
|
44
|
-
|
45
|
-
branch = values.get("branch", params.branch)
|
46
|
-
if isinstance(branch, Branch):
|
47
|
-
if branch not in session.branches:
|
48
|
-
session.branches.include(branch)
|
49
|
-
elif not branch:
|
50
|
-
branch = session.new_branch()
|
51
|
-
elif isinstance(branch, str):
|
52
|
-
branch = session.split(branch)
|
53
|
-
else:
|
54
|
-
raise ValueError("Invalid branch type")
|
55
|
-
|
56
|
-
return {"params": params, "session": session, "branch": branch}
|
57
|
-
|
58
|
-
async def _execute_single(
|
59
|
-
self, ins_: Instruct, idx: int, ttl: int
|
60
|
-
) -> InstructResponse:
|
61
|
-
if self.params.verbose:
|
62
|
-
msg_ = (
|
63
|
-
(ins_.instruction[:100] + "...")
|
64
|
-
if len(ins_.instruction) > 100
|
65
|
-
else ins_.instruction
|
66
|
-
)
|
67
|
-
print(
|
68
|
-
f"\n-----Executing Instruct {idx}/{ttl}-----\n{msg_}"
|
69
|
-
if ttl
|
70
|
-
else f"\n-----Executing Instruct {idx}-----\n{msg_}"
|
71
|
-
)
|
72
|
-
|
73
|
-
branch = self.session.split(self.branch)
|
74
|
-
res = await branch.instruct(ins_, **self.params.execute_kwargs)
|
75
|
-
return InstructResponse(instruct=ins_, response=res)
|
76
|
-
|
77
|
-
async def _execute_chunk(
|
78
|
-
self, chunk: list[tuple[Instruct, int, int]]
|
79
|
-
) -> list[InstructResponse]:
|
80
|
-
# Each chunk concurrently
|
81
|
-
return await alcall(
|
82
|
-
chunk,
|
83
|
-
self._execute_single,
|
84
|
-
max_workers=self.params.inner_max_workers,
|
85
|
-
)
|
86
|
-
|
87
|
-
async def execute(self) -> list[InstructResponse]:
|
88
|
-
instructions = self.params.instruct
|
89
|
-
chunk_size = self.params.chunk_size
|
90
|
-
total = len(instructions)
|
91
|
-
|
92
|
-
if total <= chunk_size:
|
93
|
-
chunk = [(ins, i + 1, total) for i, ins in enumerate(instructions)]
|
94
|
-
return await self._execute_chunk(chunk)
|
95
|
-
|
96
|
-
responses = []
|
97
|
-
for start in range(0, total, chunk_size):
|
98
|
-
end = min(start + chunk_size, total)
|
99
|
-
chunk = [
|
100
|
-
(instructions[i], i + 1, total) for i in range(start, end)
|
101
|
-
]
|
102
|
-
chunk_responses = await self._execute_chunk(chunk)
|
103
|
-
responses.extend(chunk_responses)
|
104
|
-
|
105
|
-
return responses
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
-
#
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
4
|
-
|
5
|
-
from typing import Any
|
6
|
-
|
7
|
-
from lionagi.operatives.instruct.instruct import Instruct
|
8
|
-
from lionagi.session.session import Branch, Session
|
9
|
-
from lionagi.utils import alcall
|
10
|
-
|
11
|
-
|
12
|
-
async def run_instruct(
|
13
|
-
ins: Instruct,
|
14
|
-
session: Session,
|
15
|
-
branch: Branch,
|
16
|
-
auto_run: bool,
|
17
|
-
verbose: bool = True,
|
18
|
-
**kwargs: Any,
|
19
|
-
) -> Any:
|
20
|
-
async def run(ins_):
|
21
|
-
if verbose:
|
22
|
-
msg_ = (
|
23
|
-
ins_.instruction[:100] + "..."
|
24
|
-
if len(ins_.instruction) > 100
|
25
|
-
else ins_.instruction
|
26
|
-
)
|
27
|
-
print(f"\n-----Running instruction-----\n{msg_}")
|
28
|
-
b_ = session.split(branch)
|
29
|
-
return await run_instruct(
|
30
|
-
ins_, session, b_, False, verbose=verbose, **kwargs
|
31
|
-
)
|
32
|
-
|
33
|
-
config = {**ins.model_dump(), **kwargs}
|
34
|
-
res = await branch.operate(**config)
|
35
|
-
branch.msgs.logger.dump()
|
36
|
-
instructs = []
|
37
|
-
|
38
|
-
if hasattr(res, "instruct_models"):
|
39
|
-
instructs = res.instruct_models
|
40
|
-
|
41
|
-
if auto_run is True and instructs:
|
42
|
-
ress = await alcall(instructs, run)
|
43
|
-
response_ = []
|
44
|
-
for res in ress:
|
45
|
-
if isinstance(res, list):
|
46
|
-
response_.extend(res)
|
47
|
-
else:
|
48
|
-
response_.append(res)
|
49
|
-
response_.insert(0, res)
|
50
|
-
return response_
|
51
|
-
|
52
|
-
return res
|
lionagi/operatives/types.py
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
-
#
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
4
|
-
|
5
|
-
from .action.function_calling import FunctionCalling
|
6
|
-
from .action.manager import ActionManager
|
7
|
-
from .action.request_response_model import (
|
8
|
-
ActionRequestModel,
|
9
|
-
ActionResponseModel,
|
10
|
-
)
|
11
|
-
from .action.tool import FuncTool, FuncToolRef, Tool, ToolRef
|
12
|
-
from .forms.base import BaseForm
|
13
|
-
from .forms.flow import FlowDefinition, FlowStep
|
14
|
-
from .forms.form import Form
|
15
|
-
from .forms.report import Report
|
16
|
-
from .instruct.base import (
|
17
|
-
ACTIONS_FIELD,
|
18
|
-
CONTEXT_FIELD,
|
19
|
-
GUIDANCE_FIELD,
|
20
|
-
INSTRUCTION_FIELD,
|
21
|
-
REASON_FIELD,
|
22
|
-
)
|
23
|
-
from .instruct.instruct import (
|
24
|
-
INSTRUCT_FIELD,
|
25
|
-
LIST_INSTRUCT_FIELD_MODEL,
|
26
|
-
Instruct,
|
27
|
-
InstructResponse,
|
28
|
-
)
|
29
|
-
from .instruct.node import InstructNode
|
30
|
-
from .instruct.reason import CONFIDENCE_SCORE_FIELD, REASON_FIELD, Reason
|
31
|
-
from .models.field_model import FieldModel
|
32
|
-
from .models.model_params import ModelParams
|
33
|
-
from .models.note import Note
|
34
|
-
from .models.operable_model import OperableModel
|
35
|
-
from .models.schema_model import SchemaModel
|
36
|
-
from .operative import Operative
|
37
|
-
from .step import Step
|
38
|
-
|
39
|
-
__all__ = (
|
40
|
-
"ActionManager",
|
41
|
-
"ActionRequestModel",
|
42
|
-
"ActionResponseModel",
|
43
|
-
"BaseForm",
|
44
|
-
"CONFIDENCE_SCORE_FIELD",
|
45
|
-
"CONTEXT_FIELD",
|
46
|
-
"Form",
|
47
|
-
"GUIDANCE_FIELD",
|
48
|
-
"INSTRUCT_FIELD",
|
49
|
-
"INSTRUCTION_FIELD",
|
50
|
-
"Instruct",
|
51
|
-
"InstructNode",
|
52
|
-
"InstructResponse",
|
53
|
-
"LIST_INSTRUCT_FIELD_MODEL",
|
54
|
-
"ModelParams",
|
55
|
-
"Note",
|
56
|
-
"OperableModel",
|
57
|
-
"Operative",
|
58
|
-
"REASON_FIELD",
|
59
|
-
"Reason",
|
60
|
-
"Report",
|
61
|
-
"SchemaModel",
|
62
|
-
"Step",
|
63
|
-
"Tool",
|
64
|
-
"ToolRef",
|
65
|
-
"ACTIONS_FIELD",
|
66
|
-
"FieldModel",
|
67
|
-
"FuncTool",
|
68
|
-
"FuncToolRef",
|
69
|
-
"FunctionCalling",
|
70
|
-
"FlowDefinition",
|
71
|
-
"FlowStep",
|
72
|
-
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|