lionagi 0.4.0__py3-none-any.whl → 0.5.1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- lionagi/__init__.py +14 -46
- lionagi/core/__init__.py +3 -1
- lionagi/core/_class_registry.py +69 -0
- lionagi/core/action/__init__.py +3 -13
- lionagi/core/action/action_manager.py +287 -0
- lionagi/core/action/base.py +109 -0
- lionagi/core/action/function_calling.py +127 -92
- lionagi/core/action/tool.py +172 -70
- lionagi/core/action/types.py +16 -0
- lionagi/core/communication/__init__.py +3 -0
- lionagi/core/communication/action_request.py +163 -0
- lionagi/core/communication/action_response.py +149 -0
- lionagi/core/communication/assistant_response.py +161 -0
- lionagi/core/communication/base_mail.py +49 -0
- lionagi/core/communication/instruction.py +376 -0
- lionagi/core/communication/message.py +286 -0
- lionagi/core/communication/message_manager.py +530 -0
- lionagi/core/communication/system.py +116 -0
- lionagi/core/communication/templates/README.md +28 -0
- lionagi/core/communication/templates/action_request.jinja2 +5 -0
- lionagi/core/communication/templates/action_response.jinja2 +9 -0
- lionagi/core/communication/templates/assistant_response.jinja2 +2 -0
- lionagi/core/communication/templates/instruction_message.jinja2 +61 -0
- lionagi/core/communication/templates/system_message.jinja2 +11 -0
- lionagi/core/communication/templates/tool_schemas.jinja2 +7 -0
- lionagi/core/communication/types.py +27 -0
- lionagi/core/communication/utils.py +254 -0
- lionagi/core/forms/__init__.py +3 -0
- lionagi/core/forms/base.py +232 -0
- lionagi/core/forms/form.py +791 -0
- lionagi/core/forms/report.py +321 -0
- lionagi/core/forms/types.py +13 -0
- lionagi/core/forms/utils.py +26 -0
- lionagi/core/generic/__init__.py +3 -6
- lionagi/core/generic/component.py +422 -0
- lionagi/core/generic/edge.py +143 -101
- lionagi/core/generic/element.py +195 -0
- lionagi/core/generic/graph.py +297 -180
- lionagi/core/generic/log.py +151 -0
- lionagi/core/generic/log_manager.py +320 -0
- lionagi/core/generic/node.py +7 -229
- lionagi/core/generic/pile.py +1017 -0
- lionagi/core/generic/progression.py +388 -0
- lionagi/core/generic/types.py +23 -0
- lionagi/core/generic/utils.py +50 -0
- lionagi/core/models/__init__.py +5 -0
- lionagi/core/models/base.py +85 -0
- lionagi/core/models/field_model.py +122 -0
- lionagi/core/models/new_model_params.py +195 -0
- lionagi/core/models/note.py +351 -0
- lionagi/core/models/operable_model.py +392 -0
- lionagi/core/models/schema_model.py +50 -0
- lionagi/core/models/types.py +10 -0
- lionagi/core/session/__init__.py +3 -0
- lionagi/core/session/branch.py +115 -415
- lionagi/core/session/branch_mixins.py +545 -0
- lionagi/core/session/session.py +122 -257
- lionagi/core/session/types.py +8 -0
- lionagi/core/typing/__init__.py +9 -0
- lionagi/core/typing/concepts.py +132 -0
- lionagi/core/typing/config.py +15 -0
- lionagi/core/typing/id.py +221 -0
- lionagi/core/typing/pydantic_.py +33 -0
- lionagi/core/typing/typing_.py +54 -0
- lionagi/integrations/__init__.py +0 -1
- lionagi/integrations/anthropic_/AnthropicModel.py +268 -0
- lionagi/integrations/anthropic_/AnthropicService.py +117 -0
- lionagi/integrations/anthropic_/__init__.py +3 -0
- lionagi/integrations/anthropic_/anthropic_max_output_token_data.yaml +7 -0
- lionagi/integrations/anthropic_/anthropic_price_data.yaml +14 -0
- lionagi/integrations/anthropic_/api_endpoints/__init__.py +3 -0
- lionagi/integrations/anthropic_/api_endpoints/api_request.py +277 -0
- lionagi/integrations/anthropic_/api_endpoints/data_models.py +40 -0
- lionagi/integrations/anthropic_/api_endpoints/match_response.py +119 -0
- lionagi/integrations/anthropic_/api_endpoints/messages/__init__.py +3 -0
- lionagi/integrations/anthropic_/api_endpoints/messages/request/__init__.py +3 -0
- lionagi/integrations/anthropic_/api_endpoints/messages/request/message_models.py +14 -0
- lionagi/integrations/anthropic_/api_endpoints/messages/request/request_body.py +74 -0
- lionagi/integrations/anthropic_/api_endpoints/messages/response/content_models.py +32 -0
- lionagi/integrations/anthropic_/api_endpoints/messages/response/response_body.py +101 -0
- lionagi/integrations/anthropic_/api_endpoints/messages/response/usage_models.py +25 -0
- lionagi/integrations/anthropic_/version.py +5 -0
- lionagi/integrations/groq_/GroqModel.py +318 -0
- lionagi/integrations/groq_/GroqService.py +151 -0
- lionagi/integrations/groq_/__init__.py +3 -0
- lionagi/integrations/groq_/api_endpoints/data_models.py +187 -0
- lionagi/integrations/groq_/api_endpoints/groq_request.py +288 -0
- lionagi/integrations/groq_/api_endpoints/match_response.py +106 -0
- lionagi/integrations/groq_/api_endpoints/response_utils.py +105 -0
- lionagi/integrations/groq_/groq_max_output_token_data.yaml +21 -0
- lionagi/integrations/groq_/groq_price_data.yaml +58 -0
- lionagi/integrations/groq_/groq_rate_limits.yaml +105 -0
- lionagi/integrations/groq_/version.py +5 -0
- lionagi/integrations/litellm_/__init__.py +3 -0
- lionagi/integrations/litellm_/imodel.py +73 -0
- lionagi/integrations/ollama_/OllamaModel.py +244 -0
- lionagi/integrations/ollama_/OllamaService.py +142 -0
- lionagi/integrations/ollama_/__init__.py +3 -0
- lionagi/integrations/ollama_/api_endpoints/__init__.py +3 -0
- lionagi/integrations/ollama_/api_endpoints/api_request.py +179 -0
- lionagi/integrations/ollama_/api_endpoints/chat_completion/__init__.py +3 -0
- lionagi/integrations/ollama_/api_endpoints/chat_completion/message_models.py +31 -0
- lionagi/integrations/ollama_/api_endpoints/chat_completion/request_body.py +46 -0
- lionagi/integrations/ollama_/api_endpoints/chat_completion/response_body.py +67 -0
- lionagi/integrations/ollama_/api_endpoints/chat_completion/tool_models.py +49 -0
- lionagi/integrations/ollama_/api_endpoints/completion/request_body.py +72 -0
- lionagi/integrations/ollama_/api_endpoints/completion/response_body.py +59 -0
- lionagi/integrations/ollama_/api_endpoints/data_models.py +15 -0
- lionagi/integrations/ollama_/api_endpoints/embedding/request_body.py +33 -0
- lionagi/integrations/ollama_/api_endpoints/embedding/response_body.py +29 -0
- lionagi/integrations/ollama_/api_endpoints/match_data_model.py +62 -0
- lionagi/integrations/ollama_/api_endpoints/match_response.py +190 -0
- lionagi/integrations/ollama_/api_endpoints/model/__init__.py +3 -0
- lionagi/integrations/ollama_/api_endpoints/model/copy_model.py +13 -0
- lionagi/integrations/ollama_/api_endpoints/model/create_model.py +28 -0
- lionagi/integrations/ollama_/api_endpoints/model/delete_model.py +11 -0
- lionagi/integrations/ollama_/api_endpoints/model/list_model.py +60 -0
- lionagi/integrations/ollama_/api_endpoints/model/pull_model.py +34 -0
- lionagi/integrations/ollama_/api_endpoints/model/push_model.py +35 -0
- lionagi/integrations/ollama_/api_endpoints/model/show_model.py +36 -0
- lionagi/integrations/ollama_/api_endpoints/option_models.py +68 -0
- lionagi/integrations/openai_/OpenAIModel.py +418 -0
- lionagi/integrations/openai_/OpenAIService.py +426 -0
- lionagi/integrations/openai_/api_endpoints/__init__.py +3 -0
- lionagi/integrations/openai_/api_endpoints/api_request.py +277 -0
- lionagi/integrations/openai_/api_endpoints/audio/__init__.py +9 -0
- lionagi/integrations/openai_/api_endpoints/audio/speech_models.py +34 -0
- lionagi/integrations/openai_/api_endpoints/audio/transcription_models.py +136 -0
- lionagi/integrations/openai_/api_endpoints/audio/translation_models.py +41 -0
- lionagi/integrations/openai_/api_endpoints/audio/types.py +41 -0
- lionagi/integrations/openai_/api_endpoints/batch/__init__.py +17 -0
- lionagi/integrations/openai_/api_endpoints/batch/batch_models.py +146 -0
- lionagi/integrations/openai_/api_endpoints/batch/cancel_batch.py +7 -0
- lionagi/integrations/openai_/api_endpoints/batch/create_batch.py +26 -0
- lionagi/integrations/openai_/api_endpoints/batch/list_batch.py +37 -0
- lionagi/integrations/openai_/api_endpoints/batch/request_object_models.py +65 -0
- lionagi/integrations/openai_/api_endpoints/batch/retrieve_batch.py +7 -0
- lionagi/integrations/openai_/api_endpoints/batch/types.py +4 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/__init__.py +1 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/request/__init__.py +39 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/request/message_models.py +121 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/request/request_body.py +221 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/request/response_format.py +71 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/request/stream_options.py +14 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/request/tool_choice_models.py +17 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/request/tool_models.py +54 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/request/types.py +18 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/response/choice_models.py +62 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/response/function_models.py +16 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/response/log_prob_models.py +47 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/response/message_models.py +25 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/response/response_body.py +99 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/response/types.py +8 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/response/usage_models.py +24 -0
- lionagi/integrations/openai_/api_endpoints/chat_completions/util.py +46 -0
- lionagi/integrations/openai_/api_endpoints/data_models.py +23 -0
- lionagi/integrations/openai_/api_endpoints/embeddings/__init__.py +3 -0
- lionagi/integrations/openai_/api_endpoints/embeddings/request_body.py +79 -0
- lionagi/integrations/openai_/api_endpoints/embeddings/response_body.py +67 -0
- lionagi/integrations/openai_/api_endpoints/files/__init__.py +11 -0
- lionagi/integrations/openai_/api_endpoints/files/delete_file.py +20 -0
- lionagi/integrations/openai_/api_endpoints/files/file_models.py +56 -0
- lionagi/integrations/openai_/api_endpoints/files/list_files.py +27 -0
- lionagi/integrations/openai_/api_endpoints/files/retrieve_file.py +9 -0
- lionagi/integrations/openai_/api_endpoints/files/upload_file.py +38 -0
- lionagi/integrations/openai_/api_endpoints/fine_tuning/__init__.py +37 -0
- lionagi/integrations/openai_/api_endpoints/fine_tuning/cancel_jobs.py +9 -0
- lionagi/integrations/openai_/api_endpoints/fine_tuning/create_jobs.py +133 -0
- lionagi/integrations/openai_/api_endpoints/fine_tuning/fine_tuning_job_checkpoint_models.py +58 -0
- lionagi/integrations/openai_/api_endpoints/fine_tuning/fine_tuning_job_event_models.py +31 -0
- lionagi/integrations/openai_/api_endpoints/fine_tuning/fine_tuning_job_models.py +140 -0
- lionagi/integrations/openai_/api_endpoints/fine_tuning/list_fine_tuning_checkpoints.py +51 -0
- lionagi/integrations/openai_/api_endpoints/fine_tuning/list_fine_tuning_events.py +42 -0
- lionagi/integrations/openai_/api_endpoints/fine_tuning/list_fine_tuning_jobs.py +31 -0
- lionagi/integrations/openai_/api_endpoints/fine_tuning/retrieve_jobs.py +9 -0
- lionagi/integrations/openai_/api_endpoints/fine_tuning/training_format.py +30 -0
- lionagi/integrations/openai_/api_endpoints/images/__init__.py +9 -0
- lionagi/integrations/openai_/api_endpoints/images/image_edit_models.py +69 -0
- lionagi/integrations/openai_/api_endpoints/images/image_models.py +56 -0
- lionagi/integrations/openai_/api_endpoints/images/image_variation_models.py +56 -0
- lionagi/integrations/openai_/api_endpoints/images/response_body.py +30 -0
- lionagi/integrations/openai_/api_endpoints/match_data_model.py +197 -0
- lionagi/integrations/openai_/api_endpoints/match_response.py +336 -0
- lionagi/integrations/openai_/api_endpoints/models/__init__.py +7 -0
- lionagi/integrations/openai_/api_endpoints/models/delete_fine_tuned_model.py +17 -0
- lionagi/integrations/openai_/api_endpoints/models/models_models.py +31 -0
- lionagi/integrations/openai_/api_endpoints/models/retrieve_model.py +9 -0
- lionagi/integrations/openai_/api_endpoints/moderations/__init__.py +3 -0
- lionagi/integrations/openai_/api_endpoints/moderations/request_body.py +20 -0
- lionagi/integrations/openai_/api_endpoints/moderations/response_body.py +139 -0
- lionagi/integrations/openai_/api_endpoints/uploads/__init__.py +19 -0
- lionagi/integrations/openai_/api_endpoints/uploads/add_upload_part.py +11 -0
- lionagi/integrations/openai_/api_endpoints/uploads/cancel_upload.py +7 -0
- lionagi/integrations/openai_/api_endpoints/uploads/complete_upload.py +18 -0
- lionagi/integrations/openai_/api_endpoints/uploads/create_upload.py +17 -0
- lionagi/integrations/openai_/api_endpoints/uploads/uploads_models.py +52 -0
- lionagi/integrations/openai_/image_token_calculator/image_token_calculator.py +92 -0
- lionagi/integrations/openai_/image_token_calculator/openai_image_token_data.yaml +15 -0
- lionagi/integrations/openai_/openai_max_output_token_data.yaml +12 -0
- lionagi/integrations/openai_/openai_price_data.yaml +26 -0
- lionagi/integrations/openai_/version.py +1 -0
- lionagi/integrations/pandas_/__init__.py +24 -0
- lionagi/integrations/pandas_/extend_df.py +61 -0
- lionagi/integrations/pandas_/read.py +103 -0
- lionagi/integrations/pandas_/remove_rows.py +61 -0
- lionagi/integrations/pandas_/replace_keywords.py +65 -0
- lionagi/integrations/pandas_/save.py +131 -0
- lionagi/integrations/pandas_/search_keywords.py +69 -0
- lionagi/integrations/pandas_/to_df.py +196 -0
- lionagi/integrations/pandas_/update_cells.py +54 -0
- lionagi/integrations/perplexity_/PerplexityModel.py +269 -0
- lionagi/integrations/perplexity_/PerplexityService.py +113 -0
- lionagi/integrations/perplexity_/__init__.py +3 -0
- lionagi/integrations/perplexity_/api_endpoints/api_request.py +171 -0
- lionagi/integrations/perplexity_/api_endpoints/chat_completions/request/request_body.py +121 -0
- lionagi/integrations/perplexity_/api_endpoints/chat_completions/response/response_body.py +146 -0
- lionagi/integrations/perplexity_/api_endpoints/data_models.py +63 -0
- lionagi/integrations/perplexity_/api_endpoints/match_response.py +26 -0
- lionagi/integrations/perplexity_/perplexity_max_output_token_data.yaml +3 -0
- lionagi/integrations/perplexity_/perplexity_price_data.yaml +10 -0
- lionagi/integrations/perplexity_/version.py +1 -0
- lionagi/integrations/pydantic_/__init__.py +8 -0
- lionagi/integrations/pydantic_/break_down_annotation.py +81 -0
- lionagi/integrations/pydantic_/new_model.py +208 -0
- lionagi/integrations/services.py +17 -0
- lionagi/libs/__init__.py +0 -55
- lionagi/libs/compress/models.py +62 -0
- lionagi/libs/compress/utils.py +81 -0
- lionagi/libs/constants.py +98 -0
- lionagi/libs/file/chunk.py +265 -0
- lionagi/libs/file/file_ops.py +114 -0
- lionagi/libs/file/params.py +212 -0
- lionagi/libs/file/path.py +301 -0
- lionagi/libs/file/process.py +139 -0
- lionagi/libs/file/save.py +90 -0
- lionagi/libs/file/types.py +22 -0
- lionagi/libs/func/async_calls/__init__.py +21 -0
- lionagi/libs/func/async_calls/alcall.py +157 -0
- lionagi/libs/func/async_calls/bcall.py +82 -0
- lionagi/libs/func/async_calls/mcall.py +134 -0
- lionagi/libs/func/async_calls/pcall.py +149 -0
- lionagi/libs/func/async_calls/rcall.py +185 -0
- lionagi/libs/func/async_calls/tcall.py +114 -0
- lionagi/libs/func/async_calls/ucall.py +85 -0
- lionagi/libs/func/decorators.py +277 -0
- lionagi/libs/func/lcall.py +57 -0
- lionagi/libs/func/params.py +64 -0
- lionagi/libs/func/throttle.py +119 -0
- lionagi/libs/func/types.py +39 -0
- lionagi/libs/func/utils.py +96 -0
- lionagi/libs/package/imports.py +162 -0
- lionagi/libs/package/management.py +58 -0
- lionagi/libs/package/params.py +26 -0
- lionagi/libs/package/system.py +18 -0
- lionagi/libs/package/types.py +26 -0
- lionagi/libs/parse/__init__.py +1 -0
- lionagi/libs/parse/flatten/__init__.py +9 -0
- lionagi/libs/parse/flatten/flatten.py +168 -0
- lionagi/libs/parse/flatten/params.py +52 -0
- lionagi/libs/parse/flatten/unflatten.py +79 -0
- lionagi/libs/parse/json/__init__.py +27 -0
- lionagi/libs/parse/json/as_readable.py +104 -0
- lionagi/libs/parse/json/extract.py +102 -0
- lionagi/libs/parse/json/parse.py +179 -0
- lionagi/libs/parse/json/schema.py +227 -0
- lionagi/libs/parse/json/to_json.py +71 -0
- lionagi/libs/parse/nested/__init__.py +33 -0
- lionagi/libs/parse/nested/nfilter.py +55 -0
- lionagi/libs/parse/nested/nget.py +40 -0
- lionagi/libs/parse/nested/ninsert.py +103 -0
- lionagi/libs/parse/nested/nmerge.py +155 -0
- lionagi/libs/parse/nested/npop.py +66 -0
- lionagi/libs/parse/nested/nset.py +89 -0
- lionagi/libs/parse/nested/to_flat_list.py +64 -0
- lionagi/libs/parse/nested/utils.py +185 -0
- lionagi/libs/parse/string_parse/__init__.py +11 -0
- lionagi/libs/parse/string_parse/code_block.py +73 -0
- lionagi/libs/parse/string_parse/docstring.py +179 -0
- lionagi/libs/parse/string_parse/function_.py +92 -0
- lionagi/libs/parse/type_convert/__init__.py +19 -0
- lionagi/libs/parse/type_convert/params.py +145 -0
- lionagi/libs/parse/type_convert/to_dict.py +333 -0
- lionagi/libs/parse/type_convert/to_list.py +186 -0
- lionagi/libs/parse/type_convert/to_num.py +358 -0
- lionagi/libs/parse/type_convert/to_str.py +195 -0
- lionagi/libs/parse/types.py +9 -0
- lionagi/libs/parse/validate/__init__.py +14 -0
- lionagi/libs/parse/validate/boolean.py +96 -0
- lionagi/libs/parse/validate/keys.py +150 -0
- lionagi/libs/parse/validate/mapping.py +109 -0
- lionagi/libs/parse/validate/params.py +62 -0
- lionagi/libs/parse/xml/__init__.py +10 -0
- lionagi/libs/parse/xml/convert.py +56 -0
- lionagi/libs/parse/xml/parser.py +93 -0
- lionagi/libs/string_similarity/__init__.py +32 -0
- lionagi/libs/string_similarity/algorithms.py +219 -0
- lionagi/libs/string_similarity/matcher.py +102 -0
- lionagi/libs/string_similarity/utils.py +15 -0
- lionagi/libs/utils.py +255 -0
- lionagi/operations/__init__.py +3 -6
- lionagi/operations/brainstorm/__init__.py +3 -0
- lionagi/operations/brainstorm/brainstorm.py +204 -0
- lionagi/operations/brainstorm/prompt.py +1 -0
- lionagi/operations/plan/__init__.py +3 -0
- lionagi/operations/plan/plan.py +172 -0
- lionagi/operations/plan/prompt.py +21 -0
- lionagi/operations/select/__init__.py +3 -0
- lionagi/operations/select/prompt.py +1 -0
- lionagi/operations/select/select.py +100 -0
- lionagi/operations/select/utils.py +107 -0
- lionagi/operations/utils.py +35 -0
- lionagi/protocols/adapters/adapter.py +79 -0
- lionagi/protocols/adapters/json_adapter.py +43 -0
- lionagi/protocols/adapters/pandas_adapter.py +96 -0
- lionagi/protocols/configs/__init__.py +15 -0
- lionagi/protocols/configs/branch_config.py +86 -0
- lionagi/protocols/configs/id_config.py +15 -0
- lionagi/protocols/configs/imodel_config.py +73 -0
- lionagi/protocols/configs/log_config.py +93 -0
- lionagi/protocols/configs/retry_config.py +29 -0
- lionagi/protocols/operatives/__init__.py +15 -0
- lionagi/protocols/operatives/action.py +181 -0
- lionagi/protocols/operatives/instruct.py +196 -0
- lionagi/protocols/operatives/operative.py +182 -0
- lionagi/protocols/operatives/prompts.py +232 -0
- lionagi/protocols/operatives/reason.py +56 -0
- lionagi/protocols/operatives/step.py +217 -0
- lionagi/protocols/registries/_component_registry.py +19 -0
- lionagi/protocols/registries/_pile_registry.py +26 -0
- lionagi/service/__init__.py +13 -0
- lionagi/service/complete_request_info.py +11 -0
- lionagi/service/imodel.py +125 -0
- lionagi/service/rate_limiter.py +108 -0
- lionagi/service/service.py +41 -0
- lionagi/service/service_match_util.py +131 -0
- lionagi/service/service_util.py +72 -0
- lionagi/service/token_calculator.py +51 -0
- lionagi/settings.py +136 -0
- lionagi/strategies/base.py +53 -0
- lionagi/strategies/concurrent.py +71 -0
- lionagi/strategies/concurrent_chunk.py +43 -0
- lionagi/strategies/concurrent_sequential_chunk.py +104 -0
- lionagi/strategies/params.py +128 -0
- lionagi/strategies/sequential.py +23 -0
- lionagi/strategies/sequential_chunk.py +89 -0
- lionagi/strategies/sequential_concurrent_chunk.py +100 -0
- lionagi/strategies/types.py +21 -0
- lionagi/strategies/utils.py +49 -0
- lionagi/version.py +1 -1
- lionagi-0.5.1.dist-info/METADATA +545 -0
- lionagi-0.5.1.dist-info/RECORD +373 -0
- {lionagi-0.4.0.dist-info → lionagi-0.5.1.dist-info}/WHEEL +1 -1
- lionagi/core/_setting/_setting.py +0 -59
- lionagi/core/action/README.md +0 -20
- lionagi/core/action/manual.py +0 -1
- lionagi/core/action/node.py +0 -94
- lionagi/core/action/tool_manager.py +0 -342
- lionagi/core/agent/README.md +0 -1
- lionagi/core/agent/base_agent.py +0 -82
- lionagi/core/agent/eval/README.md +0 -1
- lionagi/core/agent/eval/evaluator.py +0 -1
- lionagi/core/agent/eval/vote.py +0 -40
- lionagi/core/agent/learn/learner.py +0 -59
- lionagi/core/agent/plan/unit_template.py +0 -1
- lionagi/core/collections/README.md +0 -23
- lionagi/core/collections/__init__.py +0 -16
- lionagi/core/collections/_logger.py +0 -312
- lionagi/core/collections/abc/README.md +0 -63
- lionagi/core/collections/abc/__init__.py +0 -53
- lionagi/core/collections/abc/component.py +0 -620
- lionagi/core/collections/abc/concepts.py +0 -277
- lionagi/core/collections/abc/exceptions.py +0 -136
- lionagi/core/collections/abc/util.py +0 -45
- lionagi/core/collections/exchange.py +0 -146
- lionagi/core/collections/flow.py +0 -416
- lionagi/core/collections/model.py +0 -465
- lionagi/core/collections/pile.py +0 -1232
- lionagi/core/collections/progression.py +0 -221
- lionagi/core/collections/util.py +0 -73
- lionagi/core/director/README.md +0 -1
- lionagi/core/director/direct.py +0 -298
- lionagi/core/director/director.py +0 -2
- lionagi/core/director/operations/select.py +0 -3
- lionagi/core/director/operations/utils.py +0 -6
- lionagi/core/engine/branch_engine.py +0 -361
- lionagi/core/engine/instruction_map_engine.py +0 -213
- lionagi/core/engine/sandbox_.py +0 -16
- lionagi/core/engine/script_engine.py +0 -89
- lionagi/core/executor/base_executor.py +0 -97
- lionagi/core/executor/graph_executor.py +0 -335
- lionagi/core/executor/neo4j_executor.py +0 -394
- lionagi/core/generic/README.md +0 -0
- lionagi/core/generic/edge_condition.py +0 -17
- lionagi/core/generic/hyperedge.py +0 -1
- lionagi/core/generic/tree.py +0 -49
- lionagi/core/generic/tree_node.py +0 -85
- lionagi/core/mail/__init__.py +0 -11
- lionagi/core/mail/mail.py +0 -26
- lionagi/core/mail/mail_manager.py +0 -185
- lionagi/core/mail/package.py +0 -49
- lionagi/core/mail/start_mail.py +0 -36
- lionagi/core/message/__init__.py +0 -18
- lionagi/core/message/action_request.py +0 -114
- lionagi/core/message/action_response.py +0 -121
- lionagi/core/message/assistant_response.py +0 -80
- lionagi/core/message/instruction.py +0 -194
- lionagi/core/message/message.py +0 -86
- lionagi/core/message/system.py +0 -71
- lionagi/core/message/util.py +0 -274
- lionagi/core/report/__init__.py +0 -4
- lionagi/core/report/base.py +0 -201
- lionagi/core/report/form.py +0 -212
- lionagi/core/report/report.py +0 -150
- lionagi/core/report/util.py +0 -15
- lionagi/core/rule/_default.py +0 -17
- lionagi/core/rule/action.py +0 -87
- lionagi/core/rule/base.py +0 -234
- lionagi/core/rule/boolean.py +0 -56
- lionagi/core/rule/choice.py +0 -48
- lionagi/core/rule/mapping.py +0 -82
- lionagi/core/rule/number.py +0 -73
- lionagi/core/rule/rulebook.py +0 -45
- lionagi/core/rule/string.py +0 -43
- lionagi/core/rule/util.py +0 -0
- lionagi/core/session/directive_mixin.py +0 -307
- lionagi/core/structure/__init__.py +0 -1
- lionagi/core/structure/chain.py +0 -1
- lionagi/core/structure/forest.py +0 -1
- lionagi/core/structure/graph.py +0 -1
- lionagi/core/structure/tree.py +0 -1
- lionagi/core/unit/__init__.py +0 -4
- lionagi/core/unit/parallel_unit.py +0 -234
- lionagi/core/unit/template/action.py +0 -65
- lionagi/core/unit/template/base.py +0 -35
- lionagi/core/unit/template/plan.py +0 -69
- lionagi/core/unit/template/predict.py +0 -95
- lionagi/core/unit/template/score.py +0 -108
- lionagi/core/unit/template/select.py +0 -91
- lionagi/core/unit/unit.py +0 -452
- lionagi/core/unit/unit_form.py +0 -290
- lionagi/core/unit/unit_mixin.py +0 -1166
- lionagi/core/unit/util.py +0 -103
- lionagi/core/validator/validator.py +0 -376
- lionagi/core/work/work.py +0 -59
- lionagi/core/work/work_edge.py +0 -102
- lionagi/core/work/work_function.py +0 -114
- lionagi/core/work/work_function_node.py +0 -50
- lionagi/core/work/work_queue.py +0 -90
- lionagi/core/work/work_task.py +0 -151
- lionagi/core/work/worker.py +0 -410
- lionagi/core/work/worker_engine.py +0 -208
- lionagi/core/work/worklog.py +0 -108
- lionagi/experimental/compressor/base.py +0 -47
- lionagi/experimental/compressor/llm_compressor.py +0 -265
- lionagi/experimental/compressor/llm_summarizer.py +0 -61
- lionagi/experimental/compressor/util.py +0 -70
- lionagi/experimental/directive/README.md +0 -1
- lionagi/experimental/directive/__init__.py +0 -19
- lionagi/experimental/directive/parser/base_parser.py +0 -294
- lionagi/experimental/directive/parser/base_syntax.txt +0 -200
- lionagi/experimental/directive/template/base_template.py +0 -71
- lionagi/experimental/directive/template/schema.py +0 -36
- lionagi/experimental/directive/tokenizer.py +0 -59
- lionagi/experimental/evaluator/README.md +0 -1
- lionagi/experimental/evaluator/ast_evaluator.py +0 -119
- lionagi/experimental/evaluator/base_evaluator.py +0 -213
- lionagi/experimental/knowledge/__init__.py +0 -0
- lionagi/experimental/knowledge/base.py +0 -10
- lionagi/experimental/knowledge/graph.py +0 -0
- lionagi/experimental/memory/__init__.py +0 -0
- lionagi/experimental/strategies/__init__.py +0 -0
- lionagi/experimental/strategies/base.py +0 -1
- lionagi/integrations/bridge/__init__.py +0 -4
- lionagi/integrations/bridge/autogen_/__init__.py +0 -0
- lionagi/integrations/bridge/autogen_/autogen_.py +0 -127
- lionagi/integrations/bridge/langchain_/__init__.py +0 -0
- lionagi/integrations/bridge/langchain_/documents.py +0 -138
- lionagi/integrations/bridge/langchain_/langchain_bridge.py +0 -68
- lionagi/integrations/bridge/llamaindex_/__init__.py +0 -0
- lionagi/integrations/bridge/llamaindex_/index.py +0 -36
- lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +0 -108
- lionagi/integrations/bridge/llamaindex_/llama_pack.py +0 -256
- lionagi/integrations/bridge/llamaindex_/node_parser.py +0 -92
- lionagi/integrations/bridge/llamaindex_/reader.py +0 -201
- lionagi/integrations/bridge/llamaindex_/textnode.py +0 -59
- lionagi/integrations/bridge/pydantic_/__init__.py +0 -0
- lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +0 -7
- lionagi/integrations/bridge/transformers_/__init__.py +0 -0
- lionagi/integrations/bridge/transformers_/install_.py +0 -39
- lionagi/integrations/chunker/__init__.py +0 -0
- lionagi/integrations/chunker/chunk.py +0 -314
- lionagi/integrations/config/__init__.py +0 -4
- lionagi/integrations/config/mlx_configs.py +0 -1
- lionagi/integrations/config/oai_configs.py +0 -154
- lionagi/integrations/config/ollama_configs.py +0 -1
- lionagi/integrations/config/openrouter_configs.py +0 -74
- lionagi/integrations/langchain_/__init__.py +0 -0
- lionagi/integrations/llamaindex_/__init__.py +0 -0
- lionagi/integrations/loader/__init__.py +0 -0
- lionagi/integrations/loader/load.py +0 -257
- lionagi/integrations/loader/load_util.py +0 -214
- lionagi/integrations/provider/__init__.py +0 -11
- lionagi/integrations/provider/_mapping.py +0 -47
- lionagi/integrations/provider/litellm.py +0 -53
- lionagi/integrations/provider/mistralai.py +0 -1
- lionagi/integrations/provider/mlx_service.py +0 -55
- lionagi/integrations/provider/oai.py +0 -196
- lionagi/integrations/provider/ollama.py +0 -55
- lionagi/integrations/provider/openrouter.py +0 -170
- lionagi/integrations/provider/services.py +0 -138
- lionagi/integrations/provider/transformers.py +0 -108
- lionagi/integrations/storage/__init__.py +0 -3
- lionagi/integrations/storage/neo4j.py +0 -681
- lionagi/integrations/storage/storage_util.py +0 -302
- lionagi/integrations/storage/structure_excel.py +0 -291
- lionagi/integrations/storage/to_csv.py +0 -70
- lionagi/integrations/storage/to_excel.py +0 -91
- lionagi/libs/ln_api.py +0 -944
- lionagi/libs/ln_async.py +0 -208
- lionagi/libs/ln_context.py +0 -37
- lionagi/libs/ln_convert.py +0 -671
- lionagi/libs/ln_dataframe.py +0 -187
- lionagi/libs/ln_func_call.py +0 -1328
- lionagi/libs/ln_image.py +0 -114
- lionagi/libs/ln_knowledge_graph.py +0 -422
- lionagi/libs/ln_nested.py +0 -822
- lionagi/libs/ln_parse.py +0 -750
- lionagi/libs/ln_queue.py +0 -107
- lionagi/libs/ln_tokenize.py +0 -179
- lionagi/libs/ln_validate.py +0 -299
- lionagi/libs/special_tokens.py +0 -172
- lionagi/libs/sys_util.py +0 -710
- lionagi/lions/__init__.py +0 -0
- lionagi/lions/coder/__init__.py +0 -0
- lionagi/lions/coder/add_feature.py +0 -20
- lionagi/lions/coder/base_prompts.py +0 -22
- lionagi/lions/coder/code_form.py +0 -15
- lionagi/lions/coder/coder.py +0 -184
- lionagi/lions/coder/util.py +0 -101
- lionagi/lions/director/__init__.py +0 -0
- lionagi/lions/judge/__init__.py +0 -0
- lionagi/lions/judge/config.py +0 -8
- lionagi/lions/judge/data/__init__.py +0 -0
- lionagi/lions/judge/data/sample_codes.py +0 -526
- lionagi/lions/judge/data/sample_rurbic.py +0 -48
- lionagi/lions/judge/forms/__init__.py +0 -0
- lionagi/lions/judge/forms/code_analysis_form.py +0 -126
- lionagi/lions/judge/rubric.py +0 -34
- lionagi/lions/judge/services/__init__.py +0 -0
- lionagi/lions/judge/services/judge_code.py +0 -49
- lionagi/lions/researcher/__init__.py +0 -0
- lionagi/lions/researcher/data_source/__init__.py +0 -0
- lionagi/lions/researcher/data_source/finhub_.py +0 -192
- lionagi/lions/researcher/data_source/google_.py +0 -207
- lionagi/lions/researcher/data_source/wiki_.py +0 -98
- lionagi/lions/researcher/data_source/yfinance_.py +0 -21
- lionagi/operations/brainstorm.py +0 -87
- lionagi/operations/config.py +0 -6
- lionagi/operations/rank.py +0 -102
- lionagi/operations/score.py +0 -144
- lionagi/operations/select.py +0 -141
- lionagi-0.4.0.dist-info/METADATA +0 -241
- lionagi-0.4.0.dist-info/RECORD +0 -249
- /lionagi/{core/_setting → integrations/anthropic_/api_endpoints/messages/response}/__init__.py +0 -0
- /lionagi/{core/agent → integrations/groq_/api_endpoints}/__init__.py +0 -0
- /lionagi/{core/agent/eval → integrations/ollama_/api_endpoints/completion}/__init__.py +0 -0
- /lionagi/{core/agent/learn → integrations/ollama_/api_endpoints/embedding}/__init__.py +0 -0
- /lionagi/{core/agent/plan → integrations/openai_}/__init__.py +0 -0
- /lionagi/{core/director → integrations/openai_/api_endpoints/chat_completions/response}/__init__.py +0 -0
- /lionagi/{core/director/operations → integrations/openai_/image_token_calculator}/__init__.py +0 -0
- /lionagi/{core/engine → integrations/perplexity_/api_endpoints}/__init__.py +0 -0
- /lionagi/{core/executor → integrations/perplexity_/api_endpoints/chat_completions}/__init__.py +0 -0
- /lionagi/{core/generic/registry/component_registry → integrations/perplexity_/api_endpoints/chat_completions/request}/__init__.py +0 -0
- /lionagi/{core/rule → integrations/perplexity_/api_endpoints/chat_completions/response}/__init__.py +0 -0
- /lionagi/{core/unit/template → libs/compress}/__init__.py +0 -0
- /lionagi/{core/validator → libs/file}/__init__.py +0 -0
- /lionagi/{core/work → libs/func}/__init__.py +0 -0
- /lionagi/{experimental → libs/package}/__init__.py +0 -0
- /lionagi/{core/agent/plan/plan.py → libs/parse/params.py} +0 -0
- /lionagi/{experimental/compressor → protocols}/__init__.py +0 -0
- /lionagi/{experimental/directive/parser → protocols/adapters}/__init__.py +0 -0
- /lionagi/{experimental/directive/template → protocols/registries}/__init__.py +0 -0
- /lionagi/{experimental/evaluator → strategies}/__init__.py +0 -0
- {lionagi-0.4.0.dist-info → lionagi-0.5.1.dist-info/licenses}/LICENSE +0 -0
@@ -1,342 +0,0 @@
|
|
1
|
-
import inspect
|
2
|
-
from collections.abc import Callable
|
3
|
-
from functools import singledispatchmethod
|
4
|
-
from typing import Any, List, Tuple, Union
|
5
|
-
|
6
|
-
from lionfuncs import function_to_schema, lcall, to_dict, to_list
|
7
|
-
|
8
|
-
from lionagi.core.action.function_calling import FunctionCalling
|
9
|
-
from lionagi.core.action.tool import TOOL_TYPE, Tool
|
10
|
-
from lionagi.core.collections.abc import Actionable
|
11
|
-
|
12
|
-
|
13
|
-
class ToolManager(Actionable):
|
14
|
-
"""
|
15
|
-
Manages tools in the system. Provides functionality to register tools,
|
16
|
-
invoke them based on various input formats, and retrieve tool schemas.
|
17
|
-
"""
|
18
|
-
|
19
|
-
def __init__(self, registry: dict[str, Tool] = None) -> None:
|
20
|
-
"""
|
21
|
-
Initializes a new instance of ToolManager.
|
22
|
-
|
23
|
-
Args:
|
24
|
-
registry (dict[str, Tool], optional): A dictionary to store registered tools.
|
25
|
-
Defaults to an empty dictionary.
|
26
|
-
"""
|
27
|
-
self.registry = registry or {}
|
28
|
-
|
29
|
-
def __contains__(self, tool) -> bool:
|
30
|
-
if isinstance(tool, Tool):
|
31
|
-
return tool.name in self.registry
|
32
|
-
|
33
|
-
elif isinstance(tool, str):
|
34
|
-
return tool in self.registry
|
35
|
-
|
36
|
-
elif inspect.isfunction(tool):
|
37
|
-
return tool.__name__ in self.registry
|
38
|
-
|
39
|
-
return False
|
40
|
-
|
41
|
-
def _register_tool(
|
42
|
-
self, tool: Tool | Callable, update: bool = False
|
43
|
-
) -> bool:
|
44
|
-
"""
|
45
|
-
Registers a single tool or multiple tools based on the input type.
|
46
|
-
|
47
|
-
Args:
|
48
|
-
tool (Any): Can be a single Tool, a list of Tools, a callable, or other forms.
|
49
|
-
|
50
|
-
Raises:
|
51
|
-
TypeError: If the tools argument type is unsupported.
|
52
|
-
"""
|
53
|
-
if not update and tool in self:
|
54
|
-
raise ValueError(f"Function {tool.name} is already registered.")
|
55
|
-
if isinstance(tool, Callable):
|
56
|
-
tool = func_to_tool(tool)
|
57
|
-
tool = (
|
58
|
-
tool[0] if isinstance(tool, list) and len(tool) == 1 else tool
|
59
|
-
)
|
60
|
-
if not isinstance(tool, Tool):
|
61
|
-
raise TypeError("Please register a Tool object.")
|
62
|
-
self.registry[tool.name] = tool
|
63
|
-
return True
|
64
|
-
|
65
|
-
def update_tools(self, tools: list | Tool | Callable):
|
66
|
-
if isinstance(tools, Tool) or isinstance(tools, Callable):
|
67
|
-
return self._register_tool(tools, update=True)
|
68
|
-
else:
|
69
|
-
return all(lcall(tools, self._register_tool, update=True))
|
70
|
-
|
71
|
-
def register_tools(self, tools: list | Tool | Callable):
|
72
|
-
"""
|
73
|
-
Registers multiple Tools.
|
74
|
-
|
75
|
-
Args:
|
76
|
-
tools (list): The list of Tools to register.
|
77
|
-
|
78
|
-
Returns:
|
79
|
-
bool: True if all tools are successfully registered.
|
80
|
-
"""
|
81
|
-
if isinstance(tools, Tool) or isinstance(tools, Callable):
|
82
|
-
return self._register_tool(tools)
|
83
|
-
else:
|
84
|
-
return all(lcall(tools, self._register_tool))
|
85
|
-
|
86
|
-
async def invoke(self, func_calling=None):
|
87
|
-
"""
|
88
|
-
Invokes a function based on the provided function calling description.
|
89
|
-
|
90
|
-
Args:
|
91
|
-
func_calling (Any, optional): The function calling description, which can be:
|
92
|
-
- tuple: (name, kwargs)
|
93
|
-
- dict: {"function": name, "arguments": kwargs}
|
94
|
-
- str: JSON string of dict format
|
95
|
-
- ActionRequest object
|
96
|
-
- FunctionCalling object
|
97
|
-
|
98
|
-
Returns:
|
99
|
-
Any: The result of the function call.
|
100
|
-
|
101
|
-
Raises:
|
102
|
-
ValueError: If func_calling is None or the function is not registered.
|
103
|
-
"""
|
104
|
-
if not func_calling:
|
105
|
-
raise ValueError("func_calling is required.")
|
106
|
-
|
107
|
-
if not isinstance(func_calling, FunctionCalling):
|
108
|
-
func_calling = FunctionCalling.create(func_calling)
|
109
|
-
|
110
|
-
if func_calling.func_name in self.registry:
|
111
|
-
return await self.registry[func_calling.func_name].invoke(
|
112
|
-
func_calling=func_calling
|
113
|
-
)
|
114
|
-
|
115
|
-
raise ValueError(
|
116
|
-
f"Function {func_calling.func_name} is not registered."
|
117
|
-
)
|
118
|
-
|
119
|
-
@property
|
120
|
-
def _schema_list(self) -> list[dict[str, Any]]:
|
121
|
-
"""
|
122
|
-
Lists all tool schemas currently registered in the ToolManager.
|
123
|
-
|
124
|
-
Returns:
|
125
|
-
list[dict[str, Any]]: A list of tool schemas.
|
126
|
-
"""
|
127
|
-
return [tool.schema_ for tool in self.registry.values()]
|
128
|
-
|
129
|
-
def get_tool_schema(self, tools: TOOL_TYPE, **kwargs) -> dict:
|
130
|
-
"""
|
131
|
-
Retrieves the schema for a specific tool or all tools based on the input.
|
132
|
-
|
133
|
-
Args:
|
134
|
-
tools (TOOL_TYPE): Can be a boolean, specific tool name, Tool, or list of tools.
|
135
|
-
**kwargs: Additional keyword arguments to be merged with tool schema.
|
136
|
-
|
137
|
-
Returns:
|
138
|
-
dict: Combined tool schema and kwargs.
|
139
|
-
"""
|
140
|
-
if isinstance(tools, bool):
|
141
|
-
tool_kwarg = {"tools": self._schema_list}
|
142
|
-
return tool_kwarg | kwargs
|
143
|
-
|
144
|
-
else:
|
145
|
-
tool_kwarg = {"tools": self._get_tool_schema(tools)}
|
146
|
-
return tool_kwarg | kwargs
|
147
|
-
|
148
|
-
@singledispatchmethod
|
149
|
-
def _get_tool_schema(self, tool: Any) -> dict:
|
150
|
-
"""
|
151
|
-
Retrieves the schema for a specific tool based on its type.
|
152
|
-
|
153
|
-
Args:
|
154
|
-
tool (Any): The tool descriptor, can be a dict, Tool, str, or list.
|
155
|
-
|
156
|
-
Raises:
|
157
|
-
TypeError: If the tool type is unsupported.
|
158
|
-
"""
|
159
|
-
raise TypeError(f"Unsupported type {type(tool)}")
|
160
|
-
|
161
|
-
@_get_tool_schema.register(dict)
|
162
|
-
def _(self, tool):
|
163
|
-
"""
|
164
|
-
Assumes that the tool is a schema and returns it.
|
165
|
-
|
166
|
-
Args:
|
167
|
-
tool (dict): The tool schema.
|
168
|
-
|
169
|
-
Returns:
|
170
|
-
dict: The tool schema.
|
171
|
-
"""
|
172
|
-
return tool
|
173
|
-
|
174
|
-
@_get_tool_schema.register(Tool)
|
175
|
-
def _(self, tool):
|
176
|
-
"""
|
177
|
-
Retrieves the schema for a Tool object.
|
178
|
-
|
179
|
-
Args:
|
180
|
-
tool (Tool): The Tool object.
|
181
|
-
|
182
|
-
Returns:
|
183
|
-
dict: The tool schema.
|
184
|
-
|
185
|
-
Raises:
|
186
|
-
ValueError: If the Tool is not registered.
|
187
|
-
"""
|
188
|
-
if tool.name in self.registry:
|
189
|
-
return self.registry[tool.name].schema_
|
190
|
-
else:
|
191
|
-
err_msg = f"Function {tool.name} is not registered."
|
192
|
-
raise ValueError(err_msg)
|
193
|
-
|
194
|
-
@_get_tool_schema.register(str)
|
195
|
-
def _(self, tool):
|
196
|
-
"""
|
197
|
-
Assumes that the tool is a name and retrieves its schema.
|
198
|
-
|
199
|
-
Args:
|
200
|
-
tool (str): The tool name.
|
201
|
-
|
202
|
-
Returns:
|
203
|
-
dict: The tool schema.
|
204
|
-
|
205
|
-
Raises:
|
206
|
-
ValueError: If the tool name is not registered.
|
207
|
-
"""
|
208
|
-
if tool in self.registry:
|
209
|
-
return self.registry[tool].schema_
|
210
|
-
else:
|
211
|
-
err_msg = f"Function {tool} is not registered."
|
212
|
-
raise ValueError(err_msg)
|
213
|
-
|
214
|
-
@_get_tool_schema.register(list)
|
215
|
-
def _(self, tools):
|
216
|
-
"""
|
217
|
-
Retrieves the schema for a list of tools.
|
218
|
-
|
219
|
-
Args:
|
220
|
-
tools (list): The list of tools.
|
221
|
-
|
222
|
-
Returns:
|
223
|
-
list: A list of tool schemas.
|
224
|
-
"""
|
225
|
-
return lcall(tools, self._get_tool_schema)
|
226
|
-
|
227
|
-
def parse_tool(self, tools: TOOL_TYPE, **kwargs) -> dict:
|
228
|
-
"""
|
229
|
-
Parses and merges tool schemas based on the provided tool descriptors.
|
230
|
-
|
231
|
-
Args:
|
232
|
-
tools (TOOL_TYPE): The tools to parse, can be a single tool or list.
|
233
|
-
**kwargs: Additional keyword arguments to be merged with the tool schema.
|
234
|
-
|
235
|
-
Returns:
|
236
|
-
dict: The merged tool schema and additional arguments.
|
237
|
-
"""
|
238
|
-
if tools:
|
239
|
-
if isinstance(tools, bool):
|
240
|
-
tool_kwarg = {"tools": self._schema_list}
|
241
|
-
kwargs = tool_kwarg | kwargs
|
242
|
-
else:
|
243
|
-
tools = (
|
244
|
-
to_list(tools) if not isinstance(tools, list) else [tools]
|
245
|
-
)
|
246
|
-
tool_kwarg = {"tools": lcall(tools, self._get_tool_schema)}
|
247
|
-
kwargs = tool_kwarg | kwargs
|
248
|
-
|
249
|
-
return kwargs
|
250
|
-
|
251
|
-
@staticmethod
|
252
|
-
def parse_tool_request(response: dict) -> tuple[str, dict]:
|
253
|
-
"""
|
254
|
-
Parses a tool request from a given response dictionary.
|
255
|
-
|
256
|
-
Args:
|
257
|
-
response (dict): The response data containing the tool request.
|
258
|
-
|
259
|
-
Returns:
|
260
|
-
Tuple[str, dict]: The function name and its arguments.
|
261
|
-
|
262
|
-
Raises:
|
263
|
-
ValueError: If the response is not a valid function call.
|
264
|
-
"""
|
265
|
-
try:
|
266
|
-
func = response["action"][7:]
|
267
|
-
args = to_dict(response["arguments"])
|
268
|
-
return func, args
|
269
|
-
except Exception:
|
270
|
-
try:
|
271
|
-
func = response["recipient_name"].split(".")[-1]
|
272
|
-
args = response["parameters"]
|
273
|
-
return func, args
|
274
|
-
except:
|
275
|
-
raise ValueError("response is not a valid function call")
|
276
|
-
|
277
|
-
|
278
|
-
def func_to_tool(
|
279
|
-
func_: Callable | list[Callable],
|
280
|
-
parser: Callable | list[Callable] = None,
|
281
|
-
docstring_style: str = "google",
|
282
|
-
**kwargs,
|
283
|
-
) -> list[Tool]:
|
284
|
-
"""
|
285
|
-
Converts functions to Tool objects, optionally associating parsers with each function
|
286
|
-
and applying a specified docstring parsing style to generate tool schemas.
|
287
|
-
|
288
|
-
Args:
|
289
|
-
func_ (Callable | list[Callable]): The function(s) to convert into tool(s).
|
290
|
-
parser (Callable | list[Callable], optional): Parser(s) to associate with
|
291
|
-
the function(s). If a list is provided, it should match the length of func_.
|
292
|
-
docstring_style (str, optional): The style of the docstring parser to use when
|
293
|
-
generating tool schemas. Defaults to "google".
|
294
|
-
|
295
|
-
Returns:
|
296
|
-
list[Tool]: A list of Tool objects created from the provided function(s).
|
297
|
-
|
298
|
-
Raises:
|
299
|
-
ValueError: If the length of the parsers does not match the length of the
|
300
|
-
functions when both are provided as lists.
|
301
|
-
|
302
|
-
Examples:
|
303
|
-
# Convert a single function with a custom parser
|
304
|
-
tools = func_to_tool(my_function, my_parser)
|
305
|
-
|
306
|
-
# Convert multiple functions without parsers
|
307
|
-
tools = func_to_tool([func_one, func_two])
|
308
|
-
|
309
|
-
# Convert multiple functions with multiple parsers
|
310
|
-
tools = func_to_tool([func_one, func_two], [parser_one, parser_two])
|
311
|
-
"""
|
312
|
-
fs = []
|
313
|
-
funcs = to_list(func_, flatten=True, dropna=True)
|
314
|
-
parsers = to_list(parser, flatten=True, dropna=True)
|
315
|
-
|
316
|
-
if parser:
|
317
|
-
if len(funcs) != len(parsers) != 1:
|
318
|
-
raise ValueError(
|
319
|
-
"Length of parser must match length of func. Except if you only pass one"
|
320
|
-
)
|
321
|
-
|
322
|
-
for idx in range(len(funcs)):
|
323
|
-
f_ = lambda _f: Tool(
|
324
|
-
function=_f,
|
325
|
-
schema_=function_to_schema(_f, style=docstring_style),
|
326
|
-
parser=parsers[idx] if len(parsers) > 1 else parsers[0],
|
327
|
-
**kwargs,
|
328
|
-
)
|
329
|
-
|
330
|
-
fs.append(f_)
|
331
|
-
|
332
|
-
else:
|
333
|
-
fs = lcall(
|
334
|
-
funcs,
|
335
|
-
lambda _f: Tool(
|
336
|
-
function=_f,
|
337
|
-
schema_=function_to_schema(_f, style=docstring_style),
|
338
|
-
**kwargs,
|
339
|
-
),
|
340
|
-
)
|
341
|
-
|
342
|
-
return fs
|
lionagi/core/agent/README.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
agent as worker with structured executor
|
lionagi/core/agent/base_agent.py
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
from collections.abc import Callable
|
2
|
-
from typing import Any
|
3
|
-
|
4
|
-
from lionagi.core.executor.base_executor import BaseExecutor
|
5
|
-
from lionagi.core.generic.node import Node
|
6
|
-
from lionagi.core.mail.mail_manager import MailManager
|
7
|
-
from lionagi.core.mail.start_mail import StartMail
|
8
|
-
from lionagi.libs import AsyncUtil, func_call
|
9
|
-
|
10
|
-
|
11
|
-
class BaseAgent(Node):
|
12
|
-
|
13
|
-
def __init__(
|
14
|
-
self,
|
15
|
-
structure: BaseExecutor,
|
16
|
-
executable: BaseExecutor,
|
17
|
-
output_parser=None,
|
18
|
-
**kwargs,
|
19
|
-
) -> None:
|
20
|
-
"""
|
21
|
-
Initializes the BaseAgent instance.
|
22
|
-
|
23
|
-
Args:
|
24
|
-
structure: The structure of the agent.
|
25
|
-
executable_obj: The executable object of the agent.
|
26
|
-
output_parser: A function for parsing the agent's output (optional).
|
27
|
-
"""
|
28
|
-
super().__init__(**kwargs)
|
29
|
-
self.structure: BaseExecutor = structure
|
30
|
-
self.executable: BaseExecutor = executable
|
31
|
-
self.start: StartMail = StartMail()
|
32
|
-
self.mail_manager: MailManager = MailManager(
|
33
|
-
[self.structure, self.executable, self.start]
|
34
|
-
)
|
35
|
-
self.output_parser: Callable | None = output_parser
|
36
|
-
self.start_context: Any | None = None
|
37
|
-
|
38
|
-
async def mail_manager_control(self, refresh_time=1):
|
39
|
-
"""
|
40
|
-
Controls the mail manager execution based on the structure and executable states.
|
41
|
-
|
42
|
-
Args:
|
43
|
-
refresh_time: The time interval (in seconds) for checking the execution states (default: 1).
|
44
|
-
"""
|
45
|
-
while (
|
46
|
-
not self.structure.execute_stop or not self.executable.execute_stop
|
47
|
-
):
|
48
|
-
await AsyncUtil.sleep(refresh_time)
|
49
|
-
self.mail_manager.execute_stop = True
|
50
|
-
|
51
|
-
async def execute(self, context=None):
|
52
|
-
"""
|
53
|
-
Executes the agent with the given context and returns the parsed output (if available).
|
54
|
-
|
55
|
-
Args:
|
56
|
-
context: The initial context for the agent (optional).
|
57
|
-
|
58
|
-
Returns:
|
59
|
-
The parsed output of the agent (if available).
|
60
|
-
"""
|
61
|
-
self.start_context = context
|
62
|
-
self.start.trigger(
|
63
|
-
context=context,
|
64
|
-
structure_id=self.structure.ln_id,
|
65
|
-
executable_id=self.executable.ln_id,
|
66
|
-
)
|
67
|
-
await func_call.mcall(
|
68
|
-
[0.1, 0.1, 0.1, 0.1],
|
69
|
-
[
|
70
|
-
self.structure.execute,
|
71
|
-
self.executable.execute,
|
72
|
-
self.mail_manager.execute,
|
73
|
-
self.mail_manager_control,
|
74
|
-
],
|
75
|
-
)
|
76
|
-
|
77
|
-
self.structure.execute_stop = False
|
78
|
-
self.executable.execute_stop = False
|
79
|
-
self.mail_manager.execute_stop = False
|
80
|
-
|
81
|
-
if self.output_parser:
|
82
|
-
return self.output_parser(self)
|
@@ -1 +0,0 @@
|
|
1
|
-
TODO
|
@@ -1 +0,0 @@
|
|
1
|
-
# TODO
|
lionagi/core/agent/eval/vote.py
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# TODO
|
2
|
-
|
3
|
-
# from lionagi.libs import func_call
|
4
|
-
# import numpy as np
|
5
|
-
# from lionagi.core.form.predict import predict
|
6
|
-
# from lionagi.core.form.score import score
|
7
|
-
|
8
|
-
|
9
|
-
# async def vote(
|
10
|
-
# sentence,
|
11
|
-
# directive=predict,
|
12
|
-
# num_generations=5,
|
13
|
-
# num_output=1,
|
14
|
-
# num_scorer=5,
|
15
|
-
# score_range=(0, 100),
|
16
|
-
# num_digit=2,
|
17
|
-
# scorer_instruction=None,
|
18
|
-
# **kwargs,
|
19
|
-
# ):
|
20
|
-
# async def _inner(i):
|
21
|
-
# out_ = await directive(sentence, **kwargs)
|
22
|
-
# score_ = await score(
|
23
|
-
# out_.answer,
|
24
|
-
# context=sentence,
|
25
|
-
# instruction=scorer_instruction,
|
26
|
-
# score_range=score_range,
|
27
|
-
# num_digit=num_digit,
|
28
|
-
# num_instances=num_scorer,
|
29
|
-
# return_template=False,
|
30
|
-
# )
|
31
|
-
|
32
|
-
# out_.__setattr__("score", score_)
|
33
|
-
# return out_
|
34
|
-
|
35
|
-
# _outs = await func_call.alcall(list(range(num_generations)), _inner)
|
36
|
-
|
37
|
-
# top_index = np.argsort([i.score for i in _outs])[-num_output:]
|
38
|
-
# final_output = list(np.array(_outs)[top_index])
|
39
|
-
|
40
|
-
# return final_output[0] if len(final_output) == 1 else final_output
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# class LearningFramework:
|
2
|
-
# def __init__(self, learning_model: Any, learning_service: Any):
|
3
|
-
# self.learning_model = learning_model
|
4
|
-
# self.learning_service = learning_service
|
5
|
-
|
6
|
-
# async def learn_from_interaction(self, interaction_data: Dict[str, Any]) -> None:
|
7
|
-
# """
|
8
|
-
# Update the learning model based on interaction data.
|
9
|
-
# """
|
10
|
-
# # Update the embedded model
|
11
|
-
# self.learning_model.update(interaction_data)
|
12
|
-
|
13
|
-
# # Optionally send data to an external learning provider
|
14
|
-
# await self.learning_service.send_data_for_learning(interaction_data)
|
15
|
-
|
16
|
-
# async def adapt_response_strategy(self, context: Dict[str, Any]) -> Dict[str, Any]:
|
17
|
-
# """
|
18
|
-
# Adapt the assistant_response strategy based on learned patterns and context.
|
19
|
-
# """
|
20
|
-
# # Use the learning model to determine the adaptation strategy
|
21
|
-
# adaptation_strategy = self.learning_model.determine_strategy(context)
|
22
|
-
# return adaptation_strategy
|
23
|
-
|
24
|
-
|
25
|
-
# class LearningAgent(TaskAgent):
|
26
|
-
# def __init__(
|
27
|
-
# self, name: Optional[str] = None, learning_model: Optional[Any] = None
|
28
|
-
# ):
|
29
|
-
# super().__init__(name)
|
30
|
-
# self.learning_model = learning_model
|
31
|
-
|
32
|
-
# async def learn_from_interaction(self, interaction_data: Any):
|
33
|
-
# """
|
34
|
-
# Update the learning model based on interaction data.
|
35
|
-
# This method should be implemented to integrate specific learning algorithms.
|
36
|
-
# """
|
37
|
-
# if self.learning_model:
|
38
|
-
# # Placeholder for learning logic. Implement learning model updates based on interaction data.
|
39
|
-
# print("Learning from interaction...")
|
40
|
-
|
41
|
-
# async def adapt_response_strategy(self, instruction: Any) -> Any:
|
42
|
-
# """
|
43
|
-
# Adapt the assistant_response strategy based on what has been learned.
|
44
|
-
# Override this method to implement adaptive assistant_response strategies.
|
45
|
-
# """
|
46
|
-
# # Example implementation. Use the learning model to adapt the assistant_response strategy.
|
47
|
-
# print("Adapting assistant_response strategy based on learned patterns...")
|
48
|
-
# # Placeholder for demonstration. Implement adaptive assistant_response generation based on the learning model.
|
49
|
-
# return "Adapted assistant_response based on learning."
|
50
|
-
|
51
|
-
# async def process_instruction(self, instruction: Any) -> Any:
|
52
|
-
# """
|
53
|
-
# Process instruction with learning and adaptation.
|
54
|
-
# """
|
55
|
-
# # Incorporate learning into the instruction processing.
|
56
|
-
# response = await super().process_instruction(instruction)
|
57
|
-
# await self.learn_from_interaction(instruction)
|
58
|
-
# adapted_response = await self.adapt_response_strategy(instruction)
|
59
|
-
# return adapted_response
|
@@ -1 +0,0 @@
|
|
1
|
-
# TODO
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# LionAGI Core Collections
|
2
|
-
|
3
|
-
The `lionagi.core.collections` module provides essential data structures and abstractions for managing collections, sequences, and flows of items within the LionAGI system. These components form the foundation for efficient storage, access, and manipulation of data in AI-driven applications.
|
4
|
-
|
5
|
-
## Pile
|
6
|
-
|
7
|
-
`Pile` is a versatile container for managing collections of `Element` objects. It offers ordered and type-validated storage, flexible key access, item retrieval and assignment, inclusion and exclusion operations, homogeneity checks, iteration, and arithmetic operations. `Pile` also supports insertion, appending, and conversion to DataFrame for easy data analysis.
|
8
|
-
|
9
|
-
## Progression
|
10
|
-
|
11
|
-
`Progression` represents a sequence of items with a specific order. It provides methods for managing and manipulating the order of items, including inclusion and exclusion, item retrieval and removal, appending, extending, copying, and clearing. `Progression` supports arithmetic operations for adding and subtracting items or progressions, and offers length and iteration capabilities.
|
12
|
-
|
13
|
-
## Flow
|
14
|
-
|
15
|
-
`Flow` represents a flow of categorical sequences, allowing for the organization and management of multiple `Progression` sequences within a single structure. It provides sequence storage, a registry for sequence lookup by name, a default sequence concept, sequence retrieval and appending, registration, item removal, and iteration over sequences. `Flow` makes it convenient to work with related sequences and perform operations across multiple sequences.
|
16
|
-
|
17
|
-
## Exchange
|
18
|
-
|
19
|
-
`Exchange` is designed to handle incoming and outgoing flows of items. It uses a `Pile` to store pending items and maintains separate collections for pending incoming and outgoing items. `Exchange` provides methods for including and excluding items based on their direction (incoming or outgoing), facilitating efficient item exchange processing.
|
20
|
-
|
21
|
-
These core collections work together to provide a robust and flexible framework for managing data within the LionAGI system. They offer powerful capabilities for storing, accessing, and manipulating collections, sequences, and flows of items, enabling developers to build efficient and organized AI-driven applications.
|
22
|
-
|
23
|
-
For detailed usage examples and advanced features, please refer to the individual component documentation and upcoming tutorials.
|
@@ -1,16 +0,0 @@
|
|
1
|
-
from .exchange import Exchange
|
2
|
-
from .flow import Flow, flow
|
3
|
-
from .model import iModel
|
4
|
-
from .pile import Pile, pile
|
5
|
-
from .progression import Progression, progression
|
6
|
-
|
7
|
-
__all__ = [
|
8
|
-
"iModel",
|
9
|
-
"Pile",
|
10
|
-
"pile",
|
11
|
-
"Progression",
|
12
|
-
"progression",
|
13
|
-
"Flow",
|
14
|
-
"flow",
|
15
|
-
"Exchange",
|
16
|
-
]
|