lionagi 0.17.10__py3-none-any.whl → 0.18.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 +1 -2
- lionagi/_class_registry.py +1 -2
- lionagi/_errors.py +1 -2
- lionagi/adapters/async_postgres_adapter.py +2 -10
- lionagi/config.py +1 -2
- lionagi/fields/action.py +1 -2
- lionagi/fields/base.py +3 -0
- lionagi/fields/code.py +3 -0
- lionagi/fields/file.py +3 -0
- lionagi/fields/instruct.py +1 -2
- lionagi/fields/reason.py +1 -2
- lionagi/fields/research.py +3 -0
- lionagi/libs/__init__.py +1 -2
- lionagi/libs/file/__init__.py +1 -2
- lionagi/libs/file/chunk.py +1 -2
- lionagi/libs/file/process.py +1 -2
- lionagi/libs/schema/__init__.py +1 -2
- lionagi/libs/schema/as_readable.py +1 -2
- lionagi/libs/schema/extract_code_block.py +1 -2
- lionagi/libs/schema/extract_docstring.py +1 -2
- lionagi/libs/schema/function_to_schema.py +1 -2
- lionagi/libs/schema/load_pydantic_model_from_schema.py +1 -2
- lionagi/libs/schema/minimal_yaml.py +98 -0
- lionagi/libs/validate/__init__.py +1 -2
- lionagi/libs/validate/common_field_validators.py +1 -2
- lionagi/libs/validate/validate_boolean.py +1 -2
- lionagi/ln/fuzzy/_string_similarity.py +1 -2
- lionagi/ln/types.py +32 -5
- lionagi/models/__init__.py +1 -2
- lionagi/models/field_model.py +9 -1
- lionagi/models/hashable_model.py +4 -2
- lionagi/models/model_params.py +1 -2
- lionagi/models/operable_model.py +1 -2
- lionagi/models/schema_model.py +1 -2
- lionagi/operations/ReAct/ReAct.py +475 -239
- lionagi/operations/ReAct/__init__.py +1 -2
- lionagi/operations/ReAct/utils.py +4 -2
- lionagi/operations/__init__.py +1 -2
- lionagi/operations/act/__init__.py +2 -0
- lionagi/operations/act/act.py +206 -0
- lionagi/operations/brainstorm/__init__.py +1 -2
- lionagi/operations/brainstorm/brainstorm.py +1 -2
- lionagi/operations/brainstorm/prompt.py +1 -2
- lionagi/operations/builder.py +1 -2
- lionagi/operations/chat/__init__.py +1 -2
- lionagi/operations/chat/chat.py +131 -116
- lionagi/operations/communicate/communicate.py +102 -44
- lionagi/operations/flow.py +5 -6
- lionagi/operations/instruct/__init__.py +1 -2
- lionagi/operations/instruct/instruct.py +1 -2
- lionagi/operations/interpret/__init__.py +1 -2
- lionagi/operations/interpret/interpret.py +66 -22
- lionagi/operations/operate/__init__.py +1 -2
- lionagi/operations/operate/operate.py +213 -108
- lionagi/operations/parse/__init__.py +1 -2
- lionagi/operations/parse/parse.py +171 -144
- lionagi/operations/plan/__init__.py +1 -2
- lionagi/operations/plan/plan.py +1 -2
- lionagi/operations/plan/prompt.py +1 -2
- lionagi/operations/select/__init__.py +1 -2
- lionagi/operations/select/select.py +79 -19
- lionagi/operations/select/utils.py +2 -3
- lionagi/operations/types.py +120 -25
- lionagi/operations/utils.py +1 -2
- lionagi/protocols/__init__.py +1 -2
- lionagi/protocols/_concepts.py +1 -2
- lionagi/protocols/action/__init__.py +1 -2
- lionagi/protocols/action/function_calling.py +3 -20
- lionagi/protocols/action/manager.py +34 -4
- lionagi/protocols/action/tool.py +1 -2
- lionagi/protocols/contracts.py +1 -2
- lionagi/protocols/forms/__init__.py +1 -2
- lionagi/protocols/forms/base.py +1 -2
- lionagi/protocols/forms/flow.py +1 -2
- lionagi/protocols/forms/form.py +1 -2
- lionagi/protocols/forms/report.py +1 -2
- lionagi/protocols/generic/__init__.py +1 -2
- lionagi/protocols/generic/element.py +17 -65
- lionagi/protocols/generic/event.py +1 -2
- lionagi/protocols/generic/log.py +17 -14
- lionagi/protocols/generic/pile.py +3 -4
- lionagi/protocols/generic/processor.py +1 -2
- lionagi/protocols/generic/progression.py +1 -2
- lionagi/protocols/graph/__init__.py +1 -2
- lionagi/protocols/graph/edge.py +1 -2
- lionagi/protocols/graph/graph.py +1 -2
- lionagi/protocols/graph/node.py +1 -2
- lionagi/protocols/ids.py +1 -2
- lionagi/protocols/mail/__init__.py +1 -2
- lionagi/protocols/mail/exchange.py +1 -2
- lionagi/protocols/mail/mail.py +1 -2
- lionagi/protocols/mail/mailbox.py +1 -2
- lionagi/protocols/mail/manager.py +1 -2
- lionagi/protocols/mail/package.py +1 -2
- lionagi/protocols/messages/__init__.py +28 -2
- lionagi/protocols/messages/action_request.py +87 -186
- lionagi/protocols/messages/action_response.py +74 -133
- lionagi/protocols/messages/assistant_response.py +131 -161
- lionagi/protocols/messages/base.py +27 -20
- lionagi/protocols/messages/instruction.py +281 -626
- lionagi/protocols/messages/manager.py +113 -64
- lionagi/protocols/messages/message.py +88 -199
- lionagi/protocols/messages/system.py +53 -125
- lionagi/protocols/operatives/__init__.py +1 -2
- lionagi/protocols/operatives/operative.py +1 -2
- lionagi/protocols/operatives/step.py +1 -2
- lionagi/protocols/types.py +1 -4
- lionagi/service/connections/__init__.py +1 -2
- lionagi/service/connections/api_calling.py +1 -2
- lionagi/service/connections/endpoint.py +1 -10
- lionagi/service/connections/endpoint_config.py +1 -2
- lionagi/service/connections/header_factory.py +1 -2
- lionagi/service/connections/match_endpoint.py +1 -2
- lionagi/service/connections/mcp/__init__.py +1 -2
- lionagi/service/connections/mcp/wrapper.py +1 -2
- lionagi/service/connections/providers/__init__.py +1 -2
- lionagi/service/connections/providers/anthropic_.py +1 -2
- lionagi/service/connections/providers/claude_code_cli.py +1 -2
- lionagi/service/connections/providers/exa_.py +1 -2
- lionagi/service/connections/providers/nvidia_nim_.py +2 -27
- lionagi/service/connections/providers/oai_.py +30 -96
- lionagi/service/connections/providers/ollama_.py +4 -4
- lionagi/service/connections/providers/perplexity_.py +1 -2
- lionagi/service/hooks/__init__.py +1 -1
- lionagi/service/hooks/_types.py +1 -1
- lionagi/service/hooks/_utils.py +1 -1
- lionagi/service/hooks/hook_event.py +1 -1
- lionagi/service/hooks/hook_registry.py +1 -1
- lionagi/service/hooks/hooked_event.py +3 -4
- lionagi/service/imodel.py +1 -2
- lionagi/service/manager.py +1 -2
- lionagi/service/rate_limited_processor.py +1 -2
- lionagi/service/resilience.py +1 -2
- lionagi/service/third_party/anthropic_models.py +1 -2
- lionagi/service/third_party/claude_code.py +4 -4
- lionagi/service/third_party/openai_models.py +433 -0
- lionagi/service/token_calculator.py +1 -2
- lionagi/session/__init__.py +1 -2
- lionagi/session/branch.py +171 -180
- lionagi/session/session.py +4 -11
- lionagi/tools/__init__.py +1 -2
- lionagi/tools/base.py +1 -2
- lionagi/tools/file/__init__.py +1 -2
- lionagi/tools/file/reader.py +3 -4
- lionagi/tools/types.py +1 -2
- lionagi/utils.py +1 -2
- lionagi/version.py +1 -1
- {lionagi-0.17.10.dist-info → lionagi-0.18.0.dist-info}/METADATA +1 -2
- lionagi-0.18.0.dist-info/RECORD +191 -0
- lionagi/operations/_act/__init__.py +0 -3
- lionagi/operations/_act/act.py +0 -87
- lionagi/protocols/messages/templates/README.md +0 -28
- lionagi/protocols/messages/templates/action_request.jinja2 +0 -5
- lionagi/protocols/messages/templates/action_response.jinja2 +0 -9
- lionagi/protocols/messages/templates/assistant_response.jinja2 +0 -6
- lionagi/protocols/messages/templates/instruction_message.jinja2 +0 -61
- lionagi/protocols/messages/templates/system_message.jinja2 +0 -11
- lionagi/protocols/messages/templates/tool_schemas.jinja2 +0 -7
- lionagi/service/connections/providers/types.py +0 -28
- lionagi/service/third_party/openai_model_names.py +0 -198
- lionagi/service/types.py +0 -59
- lionagi-0.17.10.dist-info/RECORD +0 -199
- {lionagi-0.17.10.dist-info → lionagi-0.18.0.dist-info}/WHEEL +0 -0
- {lionagi-0.17.10.dist-info → lionagi-0.18.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,47 +1,26 @@
|
|
1
|
-
# Copyright (c) 2023
|
2
|
-
#
|
1
|
+
# Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
|
3
2
|
# SPDX-License-Identifier: Apache-2.0
|
4
3
|
|
5
|
-
import
|
4
|
+
import warnings
|
6
5
|
from typing import TYPE_CHECKING, Literal
|
7
6
|
|
8
7
|
from pydantic import BaseModel, JsonValue
|
9
8
|
|
10
9
|
from lionagi.fields.instruct import Instruct
|
10
|
+
from lionagi.ln.fuzzy import FuzzyMatchKeysParams
|
11
11
|
from lionagi.models import FieldModel, ModelParams
|
12
|
-
from lionagi.protocols.operatives.step import Operative, Step
|
13
12
|
from lionagi.protocols.types import Instruction, Progression, SenderRecipient
|
14
|
-
from lionagi.service.imodel import iModel
|
15
13
|
from lionagi.session.branch import AlcallParams
|
16
14
|
|
15
|
+
from ..types import ActionParam, ChatParam, HandleValidation, ParseParam
|
16
|
+
|
17
17
|
if TYPE_CHECKING:
|
18
|
+
from lionagi.protocols.operatives.step import Operative
|
19
|
+
from lionagi.service.imodel import iModel
|
18
20
|
from lionagi.session.branch import Branch, ToolRef
|
19
21
|
|
20
22
|
|
21
|
-
def
|
22
|
-
operative_model: type[BaseModel] = None,
|
23
|
-
request_model: type[BaseModel] = None,
|
24
|
-
response_format: type[BaseModel] = None,
|
25
|
-
):
|
26
|
-
if operative_model:
|
27
|
-
logging.warning(
|
28
|
-
"`operative_model` is deprecated. Use `response_format` instead."
|
29
|
-
)
|
30
|
-
if (
|
31
|
-
(operative_model and response_format)
|
32
|
-
or (operative_model and request_model)
|
33
|
-
or (response_format and request_model)
|
34
|
-
):
|
35
|
-
raise ValueError(
|
36
|
-
"Cannot specify both `operative_model` and `response_format` (or `request_model`) "
|
37
|
-
"as they are aliases of each other."
|
38
|
-
)
|
39
|
-
|
40
|
-
# Use the final chosen format
|
41
|
-
return response_format or operative_model or request_model
|
42
|
-
|
43
|
-
|
44
|
-
async def operate(
|
23
|
+
def prepare_operate_kw(
|
45
24
|
branch: "Branch",
|
46
25
|
*,
|
47
26
|
instruct: Instruct = None,
|
@@ -51,18 +30,17 @@ async def operate(
|
|
51
30
|
sender: SenderRecipient = None,
|
52
31
|
recipient: SenderRecipient = None,
|
53
32
|
progression: Progression = None,
|
54
|
-
imodel: iModel = None, # deprecated, alias of chat_model
|
55
|
-
chat_model: iModel = None,
|
33
|
+
imodel: "iModel" = None, # deprecated, alias of chat_model
|
34
|
+
chat_model: "iModel" = None,
|
56
35
|
invoke_actions: bool = True,
|
57
36
|
tool_schemas: list[dict] = None,
|
58
37
|
images: list = None,
|
59
38
|
image_detail: Literal["low", "high", "auto"] = None,
|
60
|
-
parse_model: iModel = None,
|
39
|
+
parse_model: "iModel" = None,
|
61
40
|
skip_validation: bool = False,
|
62
41
|
tools: "ToolRef" = None,
|
63
42
|
operative: "Operative" = None,
|
64
43
|
response_format: type[BaseModel] = None, # alias of operative.request_type
|
65
|
-
return_operative: bool = False,
|
66
44
|
actions: bool = False,
|
67
45
|
reason: bool = False,
|
68
46
|
call_params: AlcallParams = None,
|
@@ -72,21 +50,38 @@ async def operate(
|
|
72
50
|
exclude_fields: list | dict | None = None,
|
73
51
|
request_params: ModelParams = None,
|
74
52
|
request_param_kwargs: dict = None,
|
75
|
-
|
76
|
-
response_param_kwargs: dict = None,
|
77
|
-
handle_validation: Literal[
|
78
|
-
"raise", "return_value", "return_none"
|
79
|
-
] = "return_value",
|
53
|
+
handle_validation: HandleValidation = "return_value",
|
80
54
|
operative_model: type[BaseModel] = None,
|
81
55
|
request_model: type[BaseModel] = None,
|
82
56
|
include_token_usage_to_model: bool = False,
|
57
|
+
clear_messages: bool = False,
|
83
58
|
**kwargs,
|
84
59
|
) -> list | BaseModel | None | dict | str:
|
85
|
-
|
86
|
-
|
87
|
-
|
60
|
+
# Handle deprecated parameters
|
61
|
+
if operative_model:
|
62
|
+
warnings.warn(
|
63
|
+
"Parameter 'operative_model' is deprecated. Use 'response_format' instead.",
|
64
|
+
DeprecationWarning,
|
65
|
+
stacklevel=2,
|
66
|
+
)
|
67
|
+
if imodel:
|
68
|
+
warnings.warn(
|
69
|
+
"Parameter 'imodel' is deprecated. Use 'chat_model' instead.",
|
70
|
+
DeprecationWarning,
|
71
|
+
stacklevel=2,
|
72
|
+
)
|
88
73
|
|
89
|
-
|
74
|
+
if (
|
75
|
+
(operative_model and response_format)
|
76
|
+
or (operative_model and request_model)
|
77
|
+
or (response_format and request_model)
|
78
|
+
):
|
79
|
+
raise ValueError(
|
80
|
+
"Cannot specify both `operative_model` and `response_format` (or `request_model`) "
|
81
|
+
"as they are aliases of each other."
|
82
|
+
)
|
83
|
+
|
84
|
+
response_format = response_format or operative_model or request_model
|
90
85
|
chat_model = chat_model or imodel or branch.chat_model
|
91
86
|
parse_model = parse_model or chat_model
|
92
87
|
|
@@ -109,103 +104,213 @@ async def operate(
|
|
109
104
|
if action_strategy:
|
110
105
|
instruct.action_strategy = action_strategy
|
111
106
|
|
112
|
-
#
|
107
|
+
# Build the Operative - always create it for backwards compatibility
|
108
|
+
from lionagi.protocols.operatives.step import Step
|
109
|
+
|
113
110
|
operative = Step.request_operative(
|
114
111
|
request_params=request_params,
|
115
112
|
reason=instruct.reason,
|
116
|
-
actions=instruct.actions,
|
113
|
+
actions=instruct.actions or actions,
|
117
114
|
exclude_fields=exclude_fields,
|
118
115
|
base_type=response_format,
|
119
116
|
field_models=field_models,
|
120
117
|
**(request_param_kwargs or {}),
|
121
118
|
)
|
119
|
+
# Use the operative's request_type which is a proper Pydantic model
|
120
|
+
# created from field_models if provided
|
121
|
+
final_response_format = operative.request_type
|
122
122
|
|
123
|
-
#
|
124
|
-
|
125
|
-
tools = tools or True
|
126
|
-
|
127
|
-
# If we want to auto-invoke tools, fetch or generate the schemas
|
128
|
-
if invoke_actions and tools:
|
129
|
-
tool_schemas = tool_schemas or branch.acts.get_tool_schema(tools=tools)
|
130
|
-
|
131
|
-
# 2) Send the instruction to the chat model
|
132
|
-
ins, res = await branch.chat(
|
133
|
-
instruction=instruct.instruction,
|
123
|
+
# Build contexts
|
124
|
+
chat_param = ChatParam(
|
134
125
|
guidance=instruct.guidance,
|
135
126
|
context=instruct.context,
|
136
|
-
sender=sender,
|
137
|
-
recipient=recipient,
|
138
|
-
response_format=
|
127
|
+
sender=sender or branch.user or "user",
|
128
|
+
recipient=recipient or branch.id,
|
129
|
+
response_format=final_response_format,
|
139
130
|
progression=progression,
|
140
|
-
|
131
|
+
tool_schemas=tool_schemas,
|
141
132
|
images=images,
|
142
133
|
image_detail=image_detail,
|
143
|
-
|
144
|
-
return_ins_res_message=True,
|
134
|
+
plain_content=None,
|
145
135
|
include_token_usage_to_model=include_token_usage_to_model,
|
146
|
-
|
136
|
+
imodel=chat_model,
|
137
|
+
imodel_kw=kwargs,
|
147
138
|
)
|
148
|
-
branch.msgs.add_message(instruction=ins)
|
149
|
-
branch.msgs.add_message(assistant_response=res)
|
150
139
|
|
151
|
-
|
152
|
-
|
140
|
+
parse_param = None
|
141
|
+
if final_response_format and not skip_validation:
|
142
|
+
from ..parse.parse import get_default_call
|
153
143
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
144
|
+
parse_param = ParseParam(
|
145
|
+
response_format=final_response_format,
|
146
|
+
fuzzy_match_params=FuzzyMatchKeysParams(),
|
147
|
+
handle_validation="return_value",
|
148
|
+
alcall_params=get_default_call(),
|
149
|
+
imodel=parse_model,
|
150
|
+
imodel_kw={},
|
151
|
+
)
|
152
|
+
|
153
|
+
action_param = None
|
154
|
+
if invoke_actions and (instruct.actions or actions):
|
155
|
+
from ..act.act import _get_default_call_params
|
156
|
+
|
157
|
+
action_param = ActionParam(
|
158
|
+
action_call_params=call_params or _get_default_call_params(),
|
159
|
+
tools=tools,
|
160
|
+
strategy=action_strategy
|
161
|
+
or instruct.action_strategy
|
162
|
+
or "concurrent",
|
163
|
+
suppress_errors=True,
|
164
|
+
verbose_action=verbose_action,
|
165
|
+
)
|
166
|
+
|
167
|
+
return {
|
168
|
+
"instruction": instruct.instruction,
|
169
|
+
"chat_param": chat_param,
|
170
|
+
"parse_param": parse_param,
|
171
|
+
"action_param": action_param,
|
172
|
+
"handle_validation": handle_validation,
|
173
|
+
"invoke_actions": invoke_actions,
|
174
|
+
"skip_validation": skip_validation,
|
175
|
+
"clear_messages": clear_messages,
|
176
|
+
}
|
177
|
+
|
178
|
+
|
179
|
+
async def operate(
|
180
|
+
branch: "Branch",
|
181
|
+
instruction: JsonValue | Instruction,
|
182
|
+
chat_param: ChatParam,
|
183
|
+
action_param: ActionParam | None = None,
|
184
|
+
parse_param: ParseParam | None = None,
|
185
|
+
handle_validation: HandleValidation = "return_value",
|
186
|
+
invoke_actions: bool = True,
|
187
|
+
skip_validation: bool = False,
|
188
|
+
clear_messages: bool = False,
|
189
|
+
reason: bool = False,
|
190
|
+
field_models: list[FieldModel] | None = None,
|
191
|
+
) -> BaseModel | dict | str | None:
|
192
|
+
|
193
|
+
# 1. communicate chat context building to avoid changing parameters
|
194
|
+
# Start with base chat param
|
195
|
+
_cctx = chat_param
|
196
|
+
_pctx = (
|
197
|
+
parse_param.with_updates(handle_validation="return_value")
|
198
|
+
if parse_param
|
199
|
+
else ParseParam(
|
200
|
+
response_format=chat_param.response_format,
|
201
|
+
imodel=branch.parse_model,
|
166
202
|
handle_validation="return_value",
|
167
203
|
)
|
168
|
-
|
169
|
-
|
204
|
+
)
|
205
|
+
|
206
|
+
# Update tool schemas if needed
|
207
|
+
if tools := (action_param.tools or True) if action_param else None:
|
208
|
+
tool_schemas = branch.acts.get_tool_schema(tools=tools)
|
209
|
+
_cctx = _cctx.with_updates(tool_schemas=tool_schemas)
|
210
|
+
|
211
|
+
# Extract model class from response_format (can be class, instance, or dict)
|
212
|
+
model_class = None
|
213
|
+
if chat_param.response_format is not None:
|
214
|
+
if isinstance(chat_param.response_format, type) and issubclass(
|
215
|
+
chat_param.response_format, BaseModel
|
216
|
+
):
|
217
|
+
model_class = chat_param.response_format
|
218
|
+
elif isinstance(chat_param.response_format, BaseModel):
|
219
|
+
model_class = type(chat_param.response_format)
|
220
|
+
|
221
|
+
def normalize_field_model(fms):
|
222
|
+
if not fms:
|
223
|
+
return []
|
224
|
+
if not isinstance(fms, list):
|
225
|
+
return [fms]
|
226
|
+
return fms
|
227
|
+
|
228
|
+
fms = normalize_field_model(field_models)
|
229
|
+
operative = None
|
230
|
+
|
231
|
+
if model_class:
|
232
|
+
from lionagi.protocols.operatives.step import Step
|
233
|
+
|
234
|
+
operative = Step.request_operative(
|
235
|
+
reason=reason,
|
236
|
+
actions=bool(action_param is not None),
|
237
|
+
base_type=model_class,
|
238
|
+
field_models=fms,
|
170
239
|
)
|
240
|
+
# Update contexts with new response format
|
241
|
+
_cctx = _cctx.with_updates(response_format=operative.request_type)
|
242
|
+
_pctx = _pctx.with_updates(response_format=operative.request_type)
|
243
|
+
elif field_models:
|
244
|
+
dict_ = {}
|
245
|
+
for fm in fms:
|
246
|
+
if fm.name:
|
247
|
+
dict_[fm.name] = str(fm.annotated())
|
248
|
+
# Update contexts with dict format
|
249
|
+
_cctx = _cctx.with_updates(response_format=dict_)
|
250
|
+
_pctx = _pctx.with_updates(response_format=dict_)
|
251
|
+
|
252
|
+
from ..communicate.communicate import communicate
|
171
253
|
|
172
|
-
|
173
|
-
|
254
|
+
result = await communicate(
|
255
|
+
branch,
|
256
|
+
instruction,
|
257
|
+
_cctx,
|
258
|
+
_pctx,
|
259
|
+
clear_messages,
|
260
|
+
skip_validation=skip_validation,
|
261
|
+
request_fields=None,
|
262
|
+
)
|
263
|
+
if skip_validation:
|
264
|
+
return result
|
265
|
+
if model_class and not isinstance(result, model_class):
|
174
266
|
match handle_validation:
|
175
267
|
case "return_value":
|
176
|
-
return
|
268
|
+
return result
|
177
269
|
case "return_none":
|
178
270
|
return None
|
179
271
|
case "raise":
|
180
272
|
raise ValueError(
|
181
273
|
"Failed to parse the LLM response into the requested format."
|
182
274
|
)
|
183
|
-
|
184
|
-
# 6) If no tool invocation is needed, return result or operative
|
185
275
|
if not invoke_actions:
|
186
|
-
return
|
276
|
+
return result
|
187
277
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
)
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
# Possibly refine the operative with the tool outputs
|
203
|
-
operative = Step.respond_operative(
|
204
|
-
response_params=response_params,
|
205
|
-
operative=operative,
|
206
|
-
additional_data={"action_responses": action_response_models},
|
207
|
-
**(response_param_kwargs or {}),
|
278
|
+
requests = (
|
279
|
+
getattr(result, "action_requests", None)
|
280
|
+
if model_class
|
281
|
+
else result.get("action_requests", None)
|
282
|
+
)
|
283
|
+
|
284
|
+
action_response_models = None
|
285
|
+
if action_param and requests is not None:
|
286
|
+
from ..act.act import act
|
287
|
+
|
288
|
+
action_response_models = await act(
|
289
|
+
branch,
|
290
|
+
requests,
|
291
|
+
action_param,
|
208
292
|
)
|
209
293
|
|
210
|
-
|
211
|
-
|
294
|
+
if not action_response_models:
|
295
|
+
return result
|
296
|
+
|
297
|
+
# Filter out None values from action responses
|
298
|
+
action_response_models = [
|
299
|
+
r for r in action_response_models if r is not None
|
300
|
+
]
|
301
|
+
|
302
|
+
if not action_response_models: # All were None
|
303
|
+
return result
|
304
|
+
|
305
|
+
if not model_class: # Dict response
|
306
|
+
result.update({"action_responses": action_response_models})
|
307
|
+
return result
|
308
|
+
|
309
|
+
from lionagi.protocols.operatives.step import Step
|
310
|
+
|
311
|
+
operative.response_model = result
|
312
|
+
operative = Step.respond_operative(
|
313
|
+
operative=operative,
|
314
|
+
additional_data={"action_responses": action_response_models},
|
315
|
+
)
|
316
|
+
return operative.response_model
|