alita-sdk 0.3.379__py3-none-any.whl → 0.3.627__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.
- alita_sdk/cli/__init__.py +10 -0
- alita_sdk/cli/__main__.py +17 -0
- alita_sdk/cli/agent/__init__.py +5 -0
- alita_sdk/cli/agent/default.py +258 -0
- alita_sdk/cli/agent_executor.py +156 -0
- alita_sdk/cli/agent_loader.py +245 -0
- alita_sdk/cli/agent_ui.py +228 -0
- alita_sdk/cli/agents.py +3113 -0
- alita_sdk/cli/callbacks.py +647 -0
- alita_sdk/cli/cli.py +168 -0
- alita_sdk/cli/config.py +306 -0
- alita_sdk/cli/context/__init__.py +30 -0
- alita_sdk/cli/context/cleanup.py +198 -0
- alita_sdk/cli/context/manager.py +731 -0
- alita_sdk/cli/context/message.py +285 -0
- alita_sdk/cli/context/strategies.py +289 -0
- alita_sdk/cli/context/token_estimation.py +127 -0
- alita_sdk/cli/formatting.py +182 -0
- alita_sdk/cli/input_handler.py +419 -0
- alita_sdk/cli/inventory.py +1073 -0
- alita_sdk/cli/mcp_loader.py +315 -0
- alita_sdk/cli/testcases/__init__.py +94 -0
- alita_sdk/cli/testcases/data_generation.py +119 -0
- alita_sdk/cli/testcases/discovery.py +96 -0
- alita_sdk/cli/testcases/executor.py +84 -0
- alita_sdk/cli/testcases/logger.py +85 -0
- alita_sdk/cli/testcases/parser.py +172 -0
- alita_sdk/cli/testcases/prompts.py +91 -0
- alita_sdk/cli/testcases/reporting.py +125 -0
- alita_sdk/cli/testcases/setup.py +108 -0
- alita_sdk/cli/testcases/test_runner.py +282 -0
- alita_sdk/cli/testcases/utils.py +39 -0
- alita_sdk/cli/testcases/validation.py +90 -0
- alita_sdk/cli/testcases/workflow.py +196 -0
- alita_sdk/cli/toolkit.py +327 -0
- alita_sdk/cli/toolkit_loader.py +85 -0
- alita_sdk/cli/tools/__init__.py +43 -0
- alita_sdk/cli/tools/approval.py +224 -0
- alita_sdk/cli/tools/filesystem.py +1751 -0
- alita_sdk/cli/tools/planning.py +389 -0
- alita_sdk/cli/tools/terminal.py +414 -0
- alita_sdk/community/__init__.py +72 -12
- alita_sdk/community/inventory/__init__.py +236 -0
- alita_sdk/community/inventory/config.py +257 -0
- alita_sdk/community/inventory/enrichment.py +2137 -0
- alita_sdk/community/inventory/extractors.py +1469 -0
- alita_sdk/community/inventory/ingestion.py +3172 -0
- alita_sdk/community/inventory/knowledge_graph.py +1457 -0
- alita_sdk/community/inventory/parsers/__init__.py +218 -0
- alita_sdk/community/inventory/parsers/base.py +295 -0
- alita_sdk/community/inventory/parsers/csharp_parser.py +907 -0
- alita_sdk/community/inventory/parsers/go_parser.py +851 -0
- alita_sdk/community/inventory/parsers/html_parser.py +389 -0
- alita_sdk/community/inventory/parsers/java_parser.py +593 -0
- alita_sdk/community/inventory/parsers/javascript_parser.py +629 -0
- alita_sdk/community/inventory/parsers/kotlin_parser.py +768 -0
- alita_sdk/community/inventory/parsers/markdown_parser.py +362 -0
- alita_sdk/community/inventory/parsers/python_parser.py +604 -0
- alita_sdk/community/inventory/parsers/rust_parser.py +858 -0
- alita_sdk/community/inventory/parsers/swift_parser.py +832 -0
- alita_sdk/community/inventory/parsers/text_parser.py +322 -0
- alita_sdk/community/inventory/parsers/yaml_parser.py +370 -0
- alita_sdk/community/inventory/patterns/__init__.py +61 -0
- alita_sdk/community/inventory/patterns/ast_adapter.py +380 -0
- alita_sdk/community/inventory/patterns/loader.py +348 -0
- alita_sdk/community/inventory/patterns/registry.py +198 -0
- alita_sdk/community/inventory/presets.py +535 -0
- alita_sdk/community/inventory/retrieval.py +1403 -0
- alita_sdk/community/inventory/toolkit.py +173 -0
- alita_sdk/community/inventory/toolkit_utils.py +176 -0
- alita_sdk/community/inventory/visualize.py +1370 -0
- alita_sdk/configurations/__init__.py +1 -1
- alita_sdk/configurations/ado.py +141 -20
- alita_sdk/configurations/bitbucket.py +94 -2
- alita_sdk/configurations/confluence.py +130 -1
- alita_sdk/configurations/figma.py +76 -0
- alita_sdk/configurations/gitlab.py +91 -0
- alita_sdk/configurations/jira.py +103 -0
- alita_sdk/configurations/openapi.py +329 -0
- alita_sdk/configurations/qtest.py +72 -1
- alita_sdk/configurations/report_portal.py +96 -0
- alita_sdk/configurations/sharepoint.py +148 -0
- alita_sdk/configurations/testio.py +83 -0
- alita_sdk/configurations/testrail.py +88 -0
- alita_sdk/configurations/xray.py +93 -0
- alita_sdk/configurations/zephyr_enterprise.py +93 -0
- alita_sdk/configurations/zephyr_essential.py +75 -0
- alita_sdk/runtime/clients/artifact.py +3 -3
- alita_sdk/runtime/clients/client.py +388 -46
- alita_sdk/runtime/clients/mcp_discovery.py +342 -0
- alita_sdk/runtime/clients/mcp_manager.py +262 -0
- alita_sdk/runtime/clients/sandbox_client.py +8 -21
- alita_sdk/runtime/langchain/_constants_bkup.py +1318 -0
- alita_sdk/runtime/langchain/assistant.py +157 -39
- alita_sdk/runtime/langchain/constants.py +647 -1
- alita_sdk/runtime/langchain/document_loaders/AlitaDocxMammothLoader.py +315 -3
- alita_sdk/runtime/langchain/document_loaders/AlitaExcelLoader.py +103 -60
- alita_sdk/runtime/langchain/document_loaders/AlitaJSONLinesLoader.py +77 -0
- alita_sdk/runtime/langchain/document_loaders/AlitaJSONLoader.py +10 -4
- alita_sdk/runtime/langchain/document_loaders/AlitaPowerPointLoader.py +226 -7
- alita_sdk/runtime/langchain/document_loaders/AlitaTextLoader.py +5 -2
- alita_sdk/runtime/langchain/document_loaders/constants.py +40 -19
- alita_sdk/runtime/langchain/langraph_agent.py +405 -84
- alita_sdk/runtime/langchain/utils.py +106 -7
- alita_sdk/runtime/llms/preloaded.py +2 -6
- alita_sdk/runtime/models/mcp_models.py +61 -0
- alita_sdk/runtime/skills/__init__.py +91 -0
- alita_sdk/runtime/skills/callbacks.py +498 -0
- alita_sdk/runtime/skills/discovery.py +540 -0
- alita_sdk/runtime/skills/executor.py +610 -0
- alita_sdk/runtime/skills/input_builder.py +371 -0
- alita_sdk/runtime/skills/models.py +330 -0
- alita_sdk/runtime/skills/registry.py +355 -0
- alita_sdk/runtime/skills/skill_runner.py +330 -0
- alita_sdk/runtime/toolkits/__init__.py +31 -0
- alita_sdk/runtime/toolkits/application.py +29 -10
- alita_sdk/runtime/toolkits/artifact.py +20 -11
- alita_sdk/runtime/toolkits/datasource.py +13 -6
- alita_sdk/runtime/toolkits/mcp.py +783 -0
- alita_sdk/runtime/toolkits/mcp_config.py +1048 -0
- alita_sdk/runtime/toolkits/planning.py +178 -0
- alita_sdk/runtime/toolkits/skill_router.py +238 -0
- alita_sdk/runtime/toolkits/subgraph.py +251 -6
- alita_sdk/runtime/toolkits/tools.py +356 -69
- alita_sdk/runtime/toolkits/vectorstore.py +11 -5
- alita_sdk/runtime/tools/__init__.py +10 -3
- alita_sdk/runtime/tools/application.py +27 -6
- alita_sdk/runtime/tools/artifact.py +511 -28
- alita_sdk/runtime/tools/data_analysis.py +183 -0
- alita_sdk/runtime/tools/function.py +67 -35
- alita_sdk/runtime/tools/graph.py +10 -4
- alita_sdk/runtime/tools/image_generation.py +148 -46
- alita_sdk/runtime/tools/llm.py +1003 -128
- alita_sdk/runtime/tools/loop.py +3 -1
- alita_sdk/runtime/tools/loop_output.py +3 -1
- alita_sdk/runtime/tools/mcp_inspect_tool.py +284 -0
- alita_sdk/runtime/tools/mcp_remote_tool.py +181 -0
- alita_sdk/runtime/tools/mcp_server_tool.py +8 -5
- alita_sdk/runtime/tools/planning/__init__.py +36 -0
- alita_sdk/runtime/tools/planning/models.py +246 -0
- alita_sdk/runtime/tools/planning/wrapper.py +607 -0
- alita_sdk/runtime/tools/router.py +2 -4
- alita_sdk/runtime/tools/sandbox.py +65 -48
- alita_sdk/runtime/tools/skill_router.py +776 -0
- alita_sdk/runtime/tools/tool.py +3 -1
- alita_sdk/runtime/tools/vectorstore.py +9 -3
- alita_sdk/runtime/tools/vectorstore_base.py +70 -14
- alita_sdk/runtime/utils/AlitaCallback.py +137 -21
- alita_sdk/runtime/utils/constants.py +5 -1
- alita_sdk/runtime/utils/mcp_client.py +492 -0
- alita_sdk/runtime/utils/mcp_oauth.py +361 -0
- alita_sdk/runtime/utils/mcp_sse_client.py +434 -0
- alita_sdk/runtime/utils/mcp_tools_discovery.py +124 -0
- alita_sdk/runtime/utils/serialization.py +155 -0
- alita_sdk/runtime/utils/streamlit.py +40 -13
- alita_sdk/runtime/utils/toolkit_utils.py +30 -9
- alita_sdk/runtime/utils/utils.py +36 -0
- alita_sdk/tools/__init__.py +134 -35
- alita_sdk/tools/ado/repos/__init__.py +51 -32
- alita_sdk/tools/ado/repos/repos_wrapper.py +148 -89
- alita_sdk/tools/ado/test_plan/__init__.py +25 -9
- alita_sdk/tools/ado/test_plan/test_plan_wrapper.py +23 -1
- alita_sdk/tools/ado/utils.py +1 -18
- alita_sdk/tools/ado/wiki/__init__.py +25 -12
- alita_sdk/tools/ado/wiki/ado_wrapper.py +291 -22
- alita_sdk/tools/ado/work_item/__init__.py +26 -13
- alita_sdk/tools/ado/work_item/ado_wrapper.py +73 -11
- alita_sdk/tools/advanced_jira_mining/__init__.py +11 -8
- alita_sdk/tools/aws/delta_lake/__init__.py +13 -9
- alita_sdk/tools/aws/delta_lake/tool.py +5 -1
- alita_sdk/tools/azure_ai/search/__init__.py +11 -8
- alita_sdk/tools/azure_ai/search/api_wrapper.py +1 -1
- alita_sdk/tools/base/tool.py +5 -1
- alita_sdk/tools/base_indexer_toolkit.py +271 -84
- alita_sdk/tools/bitbucket/__init__.py +17 -11
- alita_sdk/tools/bitbucket/api_wrapper.py +59 -11
- alita_sdk/tools/bitbucket/cloud_api_wrapper.py +49 -35
- alita_sdk/tools/browser/__init__.py +5 -4
- alita_sdk/tools/carrier/__init__.py +5 -6
- alita_sdk/tools/carrier/backend_reports_tool.py +6 -6
- alita_sdk/tools/carrier/run_ui_test_tool.py +6 -6
- alita_sdk/tools/carrier/ui_reports_tool.py +5 -5
- alita_sdk/tools/chunkers/__init__.py +3 -1
- alita_sdk/tools/chunkers/code/treesitter/treesitter.py +37 -13
- alita_sdk/tools/chunkers/sematic/json_chunker.py +1 -0
- alita_sdk/tools/chunkers/sematic/markdown_chunker.py +97 -6
- alita_sdk/tools/chunkers/sematic/proposal_chunker.py +1 -1
- alita_sdk/tools/chunkers/universal_chunker.py +270 -0
- alita_sdk/tools/cloud/aws/__init__.py +10 -7
- alita_sdk/tools/cloud/azure/__init__.py +10 -7
- alita_sdk/tools/cloud/gcp/__init__.py +10 -7
- alita_sdk/tools/cloud/k8s/__init__.py +10 -7
- alita_sdk/tools/code/linter/__init__.py +10 -8
- alita_sdk/tools/code/loaders/codesearcher.py +3 -2
- alita_sdk/tools/code/sonar/__init__.py +11 -8
- alita_sdk/tools/code_indexer_toolkit.py +82 -22
- alita_sdk/tools/confluence/__init__.py +22 -16
- alita_sdk/tools/confluence/api_wrapper.py +107 -30
- alita_sdk/tools/confluence/loader.py +14 -2
- alita_sdk/tools/custom_open_api/__init__.py +12 -5
- alita_sdk/tools/elastic/__init__.py +11 -8
- alita_sdk/tools/elitea_base.py +493 -30
- alita_sdk/tools/figma/__init__.py +58 -11
- alita_sdk/tools/figma/api_wrapper.py +1235 -143
- alita_sdk/tools/figma/figma_client.py +73 -0
- alita_sdk/tools/figma/toon_tools.py +2748 -0
- alita_sdk/tools/github/__init__.py +14 -15
- alita_sdk/tools/github/github_client.py +224 -100
- alita_sdk/tools/github/graphql_client_wrapper.py +119 -33
- alita_sdk/tools/github/schemas.py +14 -5
- alita_sdk/tools/github/tool.py +5 -1
- alita_sdk/tools/github/tool_prompts.py +9 -22
- alita_sdk/tools/gitlab/__init__.py +16 -11
- alita_sdk/tools/gitlab/api_wrapper.py +218 -48
- alita_sdk/tools/gitlab_org/__init__.py +10 -9
- alita_sdk/tools/gitlab_org/api_wrapper.py +63 -64
- alita_sdk/tools/google/bigquery/__init__.py +13 -12
- alita_sdk/tools/google/bigquery/tool.py +5 -1
- alita_sdk/tools/google_places/__init__.py +11 -8
- alita_sdk/tools/google_places/api_wrapper.py +1 -1
- alita_sdk/tools/jira/__init__.py +17 -10
- alita_sdk/tools/jira/api_wrapper.py +92 -41
- alita_sdk/tools/keycloak/__init__.py +11 -8
- alita_sdk/tools/localgit/__init__.py +9 -3
- alita_sdk/tools/localgit/local_git.py +62 -54
- alita_sdk/tools/localgit/tool.py +5 -1
- alita_sdk/tools/memory/__init__.py +12 -4
- alita_sdk/tools/non_code_indexer_toolkit.py +1 -0
- alita_sdk/tools/ocr/__init__.py +11 -8
- alita_sdk/tools/openapi/__init__.py +491 -106
- alita_sdk/tools/openapi/api_wrapper.py +1368 -0
- alita_sdk/tools/openapi/tool.py +20 -0
- alita_sdk/tools/pandas/__init__.py +20 -12
- alita_sdk/tools/pandas/api_wrapper.py +38 -25
- alita_sdk/tools/pandas/dataframe/generator/base.py +3 -1
- alita_sdk/tools/postman/__init__.py +10 -9
- alita_sdk/tools/pptx/__init__.py +11 -10
- alita_sdk/tools/pptx/pptx_wrapper.py +1 -1
- alita_sdk/tools/qtest/__init__.py +31 -11
- alita_sdk/tools/qtest/api_wrapper.py +2135 -86
- alita_sdk/tools/rally/__init__.py +10 -9
- alita_sdk/tools/rally/api_wrapper.py +1 -1
- alita_sdk/tools/report_portal/__init__.py +12 -8
- alita_sdk/tools/salesforce/__init__.py +10 -8
- alita_sdk/tools/servicenow/__init__.py +17 -15
- alita_sdk/tools/servicenow/api_wrapper.py +1 -1
- alita_sdk/tools/sharepoint/__init__.py +10 -7
- alita_sdk/tools/sharepoint/api_wrapper.py +129 -38
- alita_sdk/tools/sharepoint/authorization_helper.py +191 -1
- alita_sdk/tools/sharepoint/utils.py +8 -2
- alita_sdk/tools/slack/__init__.py +10 -7
- alita_sdk/tools/slack/api_wrapper.py +2 -2
- alita_sdk/tools/sql/__init__.py +12 -9
- alita_sdk/tools/testio/__init__.py +10 -7
- alita_sdk/tools/testrail/__init__.py +11 -10
- alita_sdk/tools/testrail/api_wrapper.py +1 -1
- alita_sdk/tools/utils/__init__.py +9 -4
- alita_sdk/tools/utils/content_parser.py +103 -18
- alita_sdk/tools/utils/text_operations.py +410 -0
- alita_sdk/tools/utils/tool_prompts.py +79 -0
- alita_sdk/tools/vector_adapters/VectorStoreAdapter.py +30 -13
- alita_sdk/tools/xray/__init__.py +13 -9
- alita_sdk/tools/yagmail/__init__.py +9 -3
- alita_sdk/tools/zephyr/__init__.py +10 -7
- alita_sdk/tools/zephyr_enterprise/__init__.py +11 -7
- alita_sdk/tools/zephyr_essential/__init__.py +10 -7
- alita_sdk/tools/zephyr_essential/api_wrapper.py +30 -13
- alita_sdk/tools/zephyr_essential/client.py +2 -2
- alita_sdk/tools/zephyr_scale/__init__.py +11 -8
- alita_sdk/tools/zephyr_scale/api_wrapper.py +2 -2
- alita_sdk/tools/zephyr_squad/__init__.py +10 -7
- {alita_sdk-0.3.379.dist-info → alita_sdk-0.3.627.dist-info}/METADATA +154 -8
- alita_sdk-0.3.627.dist-info/RECORD +468 -0
- alita_sdk-0.3.627.dist-info/entry_points.txt +2 -0
- alita_sdk-0.3.379.dist-info/RECORD +0 -360
- {alita_sdk-0.3.379.dist-info → alita_sdk-0.3.627.dist-info}/WHEEL +0 -0
- {alita_sdk-0.3.379.dist-info → alita_sdk-0.3.627.dist-info}/licenses/LICENSE +0 -0
- {alita_sdk-0.3.379.dist-info → alita_sdk-0.3.627.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Inventory Retrieval Toolkit.
|
|
3
|
+
|
|
4
|
+
Provides LangChain-compatible toolkit for querying pre-built knowledge graphs.
|
|
5
|
+
This is a pure retrieval toolkit - for ingestion, use the IngestionPipeline.
|
|
6
|
+
|
|
7
|
+
The toolkit can be added to any agent to provide knowledge graph context.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from typing import Any, Optional, List, Dict, Literal, ClassVar
|
|
11
|
+
|
|
12
|
+
from langchain_core.tools import BaseTool
|
|
13
|
+
from langchain_core.tools import BaseToolkit
|
|
14
|
+
from pydantic import BaseModel, Field, ConfigDict, create_model
|
|
15
|
+
|
|
16
|
+
from .retrieval import InventoryRetrievalApiWrapper
|
|
17
|
+
from ...tools.base.tool import BaseAction
|
|
18
|
+
from ...tools.utils import clean_string, get_max_toolkit_length
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class InventoryRetrievalToolkit(BaseToolkit):
|
|
22
|
+
"""
|
|
23
|
+
Toolkit for querying pre-built Knowledge Graphs.
|
|
24
|
+
|
|
25
|
+
This toolkit provides retrieval-only access to a knowledge graph
|
|
26
|
+
that was built using the IngestionPipeline. It can be added to
|
|
27
|
+
any agent to provide codebase context.
|
|
28
|
+
|
|
29
|
+
Available tools:
|
|
30
|
+
- search_graph: Search entities by name, type, or layer
|
|
31
|
+
- get_entity: Get detailed entity info with relations
|
|
32
|
+
- get_entity_content: Retrieve source code via citation
|
|
33
|
+
- impact_analysis: Analyze upstream/downstream dependencies
|
|
34
|
+
- get_related_entities: Get related entities
|
|
35
|
+
- get_stats: Graph statistics
|
|
36
|
+
- get_citations: Citation summaries
|
|
37
|
+
- list_entities_by_type: List entities of a type
|
|
38
|
+
- list_entities_by_layer: List entities in a layer
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
tools: List[BaseTool] = []
|
|
42
|
+
toolkit_max_length: ClassVar[int] = 0
|
|
43
|
+
|
|
44
|
+
# All available tools in this toolkit
|
|
45
|
+
AVAILABLE_TOOLS: ClassVar[List[str]] = [
|
|
46
|
+
"search_graph",
|
|
47
|
+
"get_entity",
|
|
48
|
+
"get_entity_content",
|
|
49
|
+
"impact_analysis",
|
|
50
|
+
"get_related_entities",
|
|
51
|
+
"get_stats",
|
|
52
|
+
"get_citations",
|
|
53
|
+
"list_entities_by_type",
|
|
54
|
+
"list_entities_by_layer",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def toolkit_config_schema() -> BaseModel:
|
|
59
|
+
"""Return the configuration schema for this toolkit."""
|
|
60
|
+
selected_tools = {
|
|
61
|
+
x['name']: x['args_schema'].model_json_schema()
|
|
62
|
+
for x in InventoryRetrievalApiWrapper.model_construct().get_available_tools()
|
|
63
|
+
}
|
|
64
|
+
InventoryRetrievalToolkit.toolkit_max_length = get_max_toolkit_length(selected_tools)
|
|
65
|
+
|
|
66
|
+
model = create_model(
|
|
67
|
+
'inventory',
|
|
68
|
+
graph_path=(str, Field(
|
|
69
|
+
description="Path to the knowledge graph JSON file (required). "
|
|
70
|
+
"The graph should be built using IngestionPipeline."
|
|
71
|
+
)),
|
|
72
|
+
base_directory=(Optional[str], Field(
|
|
73
|
+
default=None,
|
|
74
|
+
description="Base directory for local content retrieval. "
|
|
75
|
+
"If set, get_entity_content will read from local files."
|
|
76
|
+
)),
|
|
77
|
+
selected_tools=(List[Literal[tuple(selected_tools)]], Field(
|
|
78
|
+
default=[],
|
|
79
|
+
json_schema_extra={'args_schemas': selected_tools}
|
|
80
|
+
)),
|
|
81
|
+
__config__=ConfigDict(json_schema_extra={
|
|
82
|
+
'metadata': {
|
|
83
|
+
"label": "Knowledge Graph Retrieval",
|
|
84
|
+
"icon_url": "inventory-icon.svg",
|
|
85
|
+
"max_length": InventoryRetrievalToolkit.toolkit_max_length,
|
|
86
|
+
"categories": ["knowledge management"],
|
|
87
|
+
"extra_categories": [
|
|
88
|
+
"knowledge graph",
|
|
89
|
+
"code context",
|
|
90
|
+
"impact analysis",
|
|
91
|
+
"code search"
|
|
92
|
+
],
|
|
93
|
+
"description": (
|
|
94
|
+
"Query a pre-built knowledge graph for codebase context. "
|
|
95
|
+
"Use IngestionPipeline to build the graph first."
|
|
96
|
+
),
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
)
|
|
100
|
+
return model
|
|
101
|
+
|
|
102
|
+
@classmethod
|
|
103
|
+
def get_toolkit(
|
|
104
|
+
cls,
|
|
105
|
+
selected_tools: Optional[List[str]] = None,
|
|
106
|
+
toolkit_name: str = "inventory",
|
|
107
|
+
graph_path: Optional[str] = None,
|
|
108
|
+
base_directory: Optional[str] = None,
|
|
109
|
+
source_toolkits: Optional[Dict[str, Any]] = None,
|
|
110
|
+
**kwargs
|
|
111
|
+
) -> "InventoryRetrievalToolkit":
|
|
112
|
+
"""
|
|
113
|
+
Create and return an InventoryRetrievalToolkit instance.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
selected_tools: List of tool names to include (None = all tools)
|
|
117
|
+
toolkit_name: Name for this toolkit instance
|
|
118
|
+
graph_path: Path to the knowledge graph JSON file
|
|
119
|
+
base_directory: Base directory for local content retrieval
|
|
120
|
+
source_toolkits: Dict of source toolkits for remote content retrieval
|
|
121
|
+
**kwargs: Additional configuration
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
Configured InventoryRetrievalToolkit instance
|
|
125
|
+
"""
|
|
126
|
+
# Validate selected tools
|
|
127
|
+
if selected_tools is None:
|
|
128
|
+
selected_tools = cls.AVAILABLE_TOOLS
|
|
129
|
+
else:
|
|
130
|
+
selected_tools = [t for t in selected_tools if t in cls.AVAILABLE_TOOLS]
|
|
131
|
+
if not selected_tools:
|
|
132
|
+
selected_tools = cls.AVAILABLE_TOOLS
|
|
133
|
+
|
|
134
|
+
# Create API wrapper
|
|
135
|
+
api_wrapper = InventoryRetrievalApiWrapper(
|
|
136
|
+
graph_path=graph_path or kwargs.get('graph_path', ''),
|
|
137
|
+
base_directory=base_directory or kwargs.get('base_directory'),
|
|
138
|
+
source_toolkits=source_toolkits or kwargs.get('source_toolkits', {}),
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
# Get available tools from wrapper
|
|
142
|
+
available_tools = api_wrapper.get_available_tools()
|
|
143
|
+
|
|
144
|
+
# Build tool mapping
|
|
145
|
+
tool_map = {t['name']: t for t in available_tools}
|
|
146
|
+
|
|
147
|
+
# Use clean toolkit name for context (max 1000 chars in description)
|
|
148
|
+
toolkit_context = f" [Toolkit: {clean_string(toolkit_name, 0)}]" if toolkit_name else ''
|
|
149
|
+
|
|
150
|
+
tools = []
|
|
151
|
+
for tool_name in selected_tools:
|
|
152
|
+
if tool_name in tool_map:
|
|
153
|
+
tool_info = tool_map[tool_name]
|
|
154
|
+
# Add toolkit context to description with character limit
|
|
155
|
+
description = tool_info['description']
|
|
156
|
+
if toolkit_context and len(description + toolkit_context) <= 1000:
|
|
157
|
+
description = description + toolkit_context
|
|
158
|
+
tools.append(BaseAction(
|
|
159
|
+
api_wrapper=api_wrapper,
|
|
160
|
+
name=tool_name,
|
|
161
|
+
description=description,
|
|
162
|
+
args_schema=tool_info['args_schema']
|
|
163
|
+
))
|
|
164
|
+
|
|
165
|
+
return cls(tools=tools)
|
|
166
|
+
|
|
167
|
+
def get_tools(self) -> List[BaseTool]:
|
|
168
|
+
"""Return list of tools in this toolkit."""
|
|
169
|
+
return self.tools
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
# Keep backward compatibility alias
|
|
173
|
+
InventoryToolkit = InventoryRetrievalToolkit
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Toolkit configuration and instantiation utilities for inventory ingestion.
|
|
3
|
+
|
|
4
|
+
This module provides functions to load toolkit configurations, instantiate source
|
|
5
|
+
toolkits from various sources (filesystem, GitHub, ADO), and get LLM instances
|
|
6
|
+
for entity extraction.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import re
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any, Dict, Optional
|
|
14
|
+
|
|
15
|
+
from alita_sdk.alita_client import AlitaClient
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def load_toolkit_config(toolkit_path: str) -> Dict[str, Any]:
|
|
19
|
+
"""
|
|
20
|
+
Load and parse a toolkit config JSON file.
|
|
21
|
+
|
|
22
|
+
Supports environment variable substitution for values like ${GITHUB_PAT}.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
toolkit_path: Path to the toolkit configuration JSON file
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
Dictionary containing the parsed and environment-resolved configuration
|
|
29
|
+
|
|
30
|
+
Example:
|
|
31
|
+
>>> config = load_toolkit_config("configs/github_toolkit.json")
|
|
32
|
+
>>> config['type']
|
|
33
|
+
'github'
|
|
34
|
+
"""
|
|
35
|
+
with open(toolkit_path, 'r') as f:
|
|
36
|
+
config = json.load(f)
|
|
37
|
+
|
|
38
|
+
# Recursively resolve environment variables
|
|
39
|
+
def resolve_env_vars(obj):
|
|
40
|
+
if isinstance(obj, str):
|
|
41
|
+
# Match ${VAR_NAME} pattern
|
|
42
|
+
pattern = r'\$\{([^}]+)\}'
|
|
43
|
+
matches = re.findall(pattern, obj)
|
|
44
|
+
for var_name in matches:
|
|
45
|
+
env_value = os.environ.get(var_name, '')
|
|
46
|
+
obj = obj.replace(f'${{{var_name}}}', env_value)
|
|
47
|
+
return obj
|
|
48
|
+
elif isinstance(obj, dict):
|
|
49
|
+
return {k: resolve_env_vars(v) for k, v in obj.items()}
|
|
50
|
+
elif isinstance(obj, list):
|
|
51
|
+
return [resolve_env_vars(item) for item in obj]
|
|
52
|
+
return obj
|
|
53
|
+
|
|
54
|
+
return resolve_env_vars(config)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def get_llm_for_config(
|
|
58
|
+
client: AlitaClient,
|
|
59
|
+
model: Optional[str] = None,
|
|
60
|
+
temperature: float = 0.0
|
|
61
|
+
):
|
|
62
|
+
"""
|
|
63
|
+
Get LLM instance from Alita client for entity extraction.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
client: AlitaClient instance
|
|
67
|
+
model: Model name (defaults to 'gpt-4o-mini' if not specified)
|
|
68
|
+
temperature: Temperature for the model (default 0.0 for deterministic output)
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
LLM instance configured with the specified model and parameters
|
|
72
|
+
|
|
73
|
+
Example:
|
|
74
|
+
>>> client = AlitaClient(...)
|
|
75
|
+
>>> llm = get_llm_for_config(client, model='gpt-4o', temperature=0.0)
|
|
76
|
+
"""
|
|
77
|
+
model_name = model or 'gpt-4o-mini'
|
|
78
|
+
|
|
79
|
+
return client.get_llm(
|
|
80
|
+
model_name=model_name,
|
|
81
|
+
model_config={
|
|
82
|
+
'temperature': temperature,
|
|
83
|
+
'max_tokens': 4096
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def get_source_toolkit(toolkit_config: Dict[str, Any]):
|
|
89
|
+
"""
|
|
90
|
+
Instantiate a source toolkit from configuration.
|
|
91
|
+
|
|
92
|
+
Supports filesystem, GitHub, and Azure DevOps (ADO) toolkit types. For SDK-based
|
|
93
|
+
toolkits (GitHub, ADO), automatically handles configuration mapping and toolkit
|
|
94
|
+
instantiation from the registry.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
toolkit_config: Toolkit configuration dictionary with 'type' key
|
|
98
|
+
and type-specific parameters
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
Instantiated toolkit object ready for ingestion
|
|
102
|
+
|
|
103
|
+
Raises:
|
|
104
|
+
ValueError: If toolkit type is unsupported or configuration is invalid
|
|
105
|
+
|
|
106
|
+
Example:
|
|
107
|
+
>>> # Filesystem toolkit
|
|
108
|
+
>>> config = {'type': 'filesystem', 'base_path': '/path/to/code'}
|
|
109
|
+
>>> toolkit = get_source_toolkit(config)
|
|
110
|
+
|
|
111
|
+
>>> # GitHub toolkit
|
|
112
|
+
>>> config = {
|
|
113
|
+
... 'type': 'github',
|
|
114
|
+
... 'github_token': 'ghp_...',
|
|
115
|
+
... 'github_repository': 'owner/repo',
|
|
116
|
+
... 'github_branch': 'main'
|
|
117
|
+
... }
|
|
118
|
+
>>> toolkit = get_source_toolkit(config)
|
|
119
|
+
"""
|
|
120
|
+
from alita_sdk.community.inventory.filesystem_toolkit import FilesystemToolkit
|
|
121
|
+
from alita_sdk.community.toolkits import AVAILABLE_TOOLS
|
|
122
|
+
|
|
123
|
+
toolkit_type = toolkit_config.get('type')
|
|
124
|
+
|
|
125
|
+
if toolkit_type == 'filesystem':
|
|
126
|
+
base_path = toolkit_config.get('base_path')
|
|
127
|
+
if not base_path:
|
|
128
|
+
raise ValueError("Filesystem toolkit requires 'base_path' configuration")
|
|
129
|
+
return FilesystemToolkit(base_path=Path(base_path))
|
|
130
|
+
|
|
131
|
+
# Handle SDK toolkits (GitHub, ADO)
|
|
132
|
+
if toolkit_type not in AVAILABLE_TOOLS:
|
|
133
|
+
raise ValueError(
|
|
134
|
+
f"Unknown toolkit type: {toolkit_type}. "
|
|
135
|
+
f"Available types: filesystem, {', '.join(AVAILABLE_TOOLS.keys())}"
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
toolkit_class = AVAILABLE_TOOLS[toolkit_type]
|
|
139
|
+
|
|
140
|
+
# Flatten nested config if needed
|
|
141
|
+
config_for_init = {}
|
|
142
|
+
for key, value in toolkit_config.items():
|
|
143
|
+
if key == 'type':
|
|
144
|
+
continue
|
|
145
|
+
if isinstance(value, dict):
|
|
146
|
+
# Flatten nested dicts
|
|
147
|
+
config_for_init.update(value)
|
|
148
|
+
else:
|
|
149
|
+
config_for_init[key] = value
|
|
150
|
+
|
|
151
|
+
# Map field names for specific toolkit types
|
|
152
|
+
if toolkit_type == 'github':
|
|
153
|
+
field_mapping = {
|
|
154
|
+
'github_token': 'token',
|
|
155
|
+
'github_repository': 'repository',
|
|
156
|
+
'github_branch': 'branch'
|
|
157
|
+
}
|
|
158
|
+
config_for_init = {
|
|
159
|
+
field_mapping.get(k, k): v
|
|
160
|
+
for k, v in config_for_init.items()
|
|
161
|
+
}
|
|
162
|
+
elif toolkit_type == 'ado':
|
|
163
|
+
field_mapping = {
|
|
164
|
+
'ado_token': 'token',
|
|
165
|
+
'ado_organization': 'organization',
|
|
166
|
+
'ado_project': 'project',
|
|
167
|
+
'ado_repository': 'repository',
|
|
168
|
+
'ado_branch': 'branch'
|
|
169
|
+
}
|
|
170
|
+
config_for_init = {
|
|
171
|
+
field_mapping.get(k, k): v
|
|
172
|
+
for k, v in config_for_init.items()
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
# Instantiate toolkit
|
|
176
|
+
return toolkit_class(**config_for_init)
|