langroid 0.32.2__py3-none-any.whl → 0.33.4__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.
- {langroid-0.32.2.dist-info → langroid-0.33.4.dist-info}/METADATA +149 -123
- langroid-0.33.4.dist-info/RECORD +7 -0
- {langroid-0.32.2.dist-info → langroid-0.33.4.dist-info}/WHEEL +1 -1
- langroid-0.33.4.dist-info/entry_points.txt +4 -0
- pyproject.toml +317 -212
- langroid/__init__.py +0 -106
- langroid/agent/__init__.py +0 -41
- langroid/agent/base.py +0 -1983
- langroid/agent/batch.py +0 -398
- langroid/agent/callbacks/__init__.py +0 -0
- langroid/agent/callbacks/chainlit.py +0 -598
- langroid/agent/chat_agent.py +0 -1899
- langroid/agent/chat_document.py +0 -454
- langroid/agent/openai_assistant.py +0 -882
- langroid/agent/special/__init__.py +0 -59
- langroid/agent/special/arangodb/__init__.py +0 -0
- langroid/agent/special/arangodb/arangodb_agent.py +0 -656
- langroid/agent/special/arangodb/system_messages.py +0 -186
- langroid/agent/special/arangodb/tools.py +0 -107
- langroid/agent/special/arangodb/utils.py +0 -36
- langroid/agent/special/doc_chat_agent.py +0 -1466
- langroid/agent/special/lance_doc_chat_agent.py +0 -262
- langroid/agent/special/lance_rag/__init__.py +0 -9
- langroid/agent/special/lance_rag/critic_agent.py +0 -198
- langroid/agent/special/lance_rag/lance_rag_task.py +0 -82
- langroid/agent/special/lance_rag/query_planner_agent.py +0 -260
- langroid/agent/special/lance_tools.py +0 -61
- langroid/agent/special/neo4j/__init__.py +0 -0
- langroid/agent/special/neo4j/csv_kg_chat.py +0 -174
- langroid/agent/special/neo4j/neo4j_chat_agent.py +0 -433
- langroid/agent/special/neo4j/system_messages.py +0 -120
- langroid/agent/special/neo4j/tools.py +0 -32
- langroid/agent/special/relevance_extractor_agent.py +0 -127
- langroid/agent/special/retriever_agent.py +0 -56
- langroid/agent/special/sql/__init__.py +0 -17
- langroid/agent/special/sql/sql_chat_agent.py +0 -654
- langroid/agent/special/sql/utils/__init__.py +0 -21
- langroid/agent/special/sql/utils/description_extractors.py +0 -190
- langroid/agent/special/sql/utils/populate_metadata.py +0 -85
- langroid/agent/special/sql/utils/system_message.py +0 -35
- langroid/agent/special/sql/utils/tools.py +0 -64
- langroid/agent/special/table_chat_agent.py +0 -263
- langroid/agent/task.py +0 -2095
- langroid/agent/tool_message.py +0 -393
- langroid/agent/tools/__init__.py +0 -38
- langroid/agent/tools/duckduckgo_search_tool.py +0 -50
- langroid/agent/tools/file_tools.py +0 -234
- langroid/agent/tools/google_search_tool.py +0 -39
- langroid/agent/tools/metaphor_search_tool.py +0 -67
- langroid/agent/tools/orchestration.py +0 -303
- langroid/agent/tools/recipient_tool.py +0 -235
- langroid/agent/tools/retrieval_tool.py +0 -32
- langroid/agent/tools/rewind_tool.py +0 -137
- langroid/agent/tools/segment_extract_tool.py +0 -41
- langroid/agent/xml_tool_message.py +0 -382
- langroid/cachedb/__init__.py +0 -17
- langroid/cachedb/base.py +0 -58
- langroid/cachedb/momento_cachedb.py +0 -108
- langroid/cachedb/redis_cachedb.py +0 -153
- langroid/embedding_models/__init__.py +0 -39
- langroid/embedding_models/base.py +0 -74
- langroid/embedding_models/models.py +0 -461
- langroid/embedding_models/protoc/__init__.py +0 -0
- langroid/embedding_models/protoc/embeddings.proto +0 -19
- langroid/embedding_models/protoc/embeddings_pb2.py +0 -33
- langroid/embedding_models/protoc/embeddings_pb2.pyi +0 -50
- langroid/embedding_models/protoc/embeddings_pb2_grpc.py +0 -79
- langroid/embedding_models/remote_embeds.py +0 -153
- langroid/exceptions.py +0 -65
- langroid/language_models/__init__.py +0 -53
- langroid/language_models/azure_openai.py +0 -153
- langroid/language_models/base.py +0 -678
- langroid/language_models/config.py +0 -18
- langroid/language_models/mock_lm.py +0 -124
- langroid/language_models/openai_gpt.py +0 -1964
- langroid/language_models/prompt_formatter/__init__.py +0 -16
- langroid/language_models/prompt_formatter/base.py +0 -40
- langroid/language_models/prompt_formatter/hf_formatter.py +0 -132
- langroid/language_models/prompt_formatter/llama2_formatter.py +0 -75
- langroid/language_models/utils.py +0 -151
- langroid/mytypes.py +0 -84
- langroid/parsing/__init__.py +0 -52
- langroid/parsing/agent_chats.py +0 -38
- langroid/parsing/code_parser.py +0 -121
- langroid/parsing/document_parser.py +0 -718
- langroid/parsing/para_sentence_split.py +0 -62
- langroid/parsing/parse_json.py +0 -155
- langroid/parsing/parser.py +0 -313
- langroid/parsing/repo_loader.py +0 -790
- langroid/parsing/routing.py +0 -36
- langroid/parsing/search.py +0 -275
- langroid/parsing/spider.py +0 -102
- langroid/parsing/table_loader.py +0 -94
- langroid/parsing/url_loader.py +0 -111
- langroid/parsing/urls.py +0 -273
- langroid/parsing/utils.py +0 -373
- langroid/parsing/web_search.py +0 -155
- langroid/prompts/__init__.py +0 -9
- langroid/prompts/dialog.py +0 -17
- langroid/prompts/prompts_config.py +0 -5
- langroid/prompts/templates.py +0 -141
- langroid/pydantic_v1/__init__.py +0 -10
- langroid/pydantic_v1/main.py +0 -4
- langroid/utils/__init__.py +0 -19
- langroid/utils/algorithms/__init__.py +0 -3
- langroid/utils/algorithms/graph.py +0 -103
- langroid/utils/configuration.py +0 -98
- langroid/utils/constants.py +0 -30
- langroid/utils/git_utils.py +0 -252
- langroid/utils/globals.py +0 -49
- langroid/utils/logging.py +0 -135
- langroid/utils/object_registry.py +0 -66
- langroid/utils/output/__init__.py +0 -20
- langroid/utils/output/citations.py +0 -41
- langroid/utils/output/printing.py +0 -99
- langroid/utils/output/status.py +0 -40
- langroid/utils/pandas_utils.py +0 -30
- langroid/utils/pydantic_utils.py +0 -602
- langroid/utils/system.py +0 -286
- langroid/utils/types.py +0 -93
- langroid/vector_store/__init__.py +0 -50
- langroid/vector_store/base.py +0 -357
- langroid/vector_store/chromadb.py +0 -214
- langroid/vector_store/lancedb.py +0 -401
- langroid/vector_store/meilisearch.py +0 -299
- langroid/vector_store/momento.py +0 -278
- langroid/vector_store/qdrantdb.py +0 -468
- langroid-0.32.2.dist-info/RECORD +0 -128
- {langroid-0.32.2.dist-info → langroid-0.33.4.dist-info/licenses}/LICENSE +0 -0
@@ -1,186 +0,0 @@
|
|
1
|
-
from langroid.agent.special.arangodb.tools import (
|
2
|
-
aql_creation_tool_name,
|
3
|
-
aql_retrieval_tool_name,
|
4
|
-
arango_schema_tool_name,
|
5
|
-
)
|
6
|
-
from langroid.agent.tools.orchestration import DoneTool
|
7
|
-
|
8
|
-
done_tool_name = DoneTool.default_value("request")
|
9
|
-
|
10
|
-
arango_schema_tool_description = f"""
|
11
|
-
`{arango_schema_tool_name}` tool/function-call to find the schema
|
12
|
-
of the graph database, or for some SPECIFIC collections, i.e. get information on
|
13
|
-
(document and edge), their attributes, and graph definitions available in your
|
14
|
-
ArangoDB database. You MUST use this tool BEFORE attempting to use the
|
15
|
-
`{aql_retrieval_tool_name}` tool/function-call, to ensure that you are using the
|
16
|
-
correct collection names and attributes in your `{aql_retrieval_tool_name}` tool.
|
17
|
-
"""
|
18
|
-
|
19
|
-
aql_retrieval_tool_description = f"""
|
20
|
-
`{aql_retrieval_tool_name}` tool/function-call to retrieve information from
|
21
|
-
the database using AQL (ArangoDB Query Language) queries, to answer
|
22
|
-
the user's questions, OR for you to learn more about the SCHEMA of the database.
|
23
|
-
"""
|
24
|
-
|
25
|
-
aql_creation_tool_description = f"""
|
26
|
-
`{aql_creation_tool_name}` tool/function-call to execute AQL query that creates
|
27
|
-
documents/edges in the database.
|
28
|
-
"""
|
29
|
-
|
30
|
-
aql_retrieval_query_example = """
|
31
|
-
EXAMPLE:
|
32
|
-
Suppose you are asked this question "Does Bob have a father?".
|
33
|
-
Then you will go through the following steps, where YOU indicates
|
34
|
-
the message YOU will be sending, and RESULTS indicates the RESULTS
|
35
|
-
you will receive from the helper executing the query:
|
36
|
-
|
37
|
-
1. YOU:
|
38
|
-
{{ "request": "aql_retrieval_tool",
|
39
|
-
"aql_query": "FOR v, e, p in ... [query truncated for brevity]..."}}
|
40
|
-
|
41
|
-
2. RESULTS:
|
42
|
-
[.. results from the query...]
|
43
|
-
3. YOU: [ since results were not satisfactory, you try ANOTHER query]
|
44
|
-
{{ "request": "aql_retrieval_tool",
|
45
|
-
"aql_query": "blah blah ... [query truncated for brevity]..."}}
|
46
|
-
}}
|
47
|
-
4. RESULTS:
|
48
|
-
[.. results from the query...]
|
49
|
-
5. YOU: [ now you have the answer, you can generate your response ]
|
50
|
-
The answer is YES, Bob has a father, and his name is John.
|
51
|
-
"""
|
52
|
-
|
53
|
-
aql_query_instructions = """
|
54
|
-
When writing AQL queries:
|
55
|
-
1. Use the exact property names shown in the schema
|
56
|
-
2. Pay attention to the 'type' field of each node
|
57
|
-
3. Note that all names are case-sensitive:
|
58
|
-
- collection names
|
59
|
-
- property names
|
60
|
-
- node type values
|
61
|
-
- relationship type values
|
62
|
-
4. Always include type filters in your queries, e.g.:
|
63
|
-
FILTER doc.type == '<type-from-schema>'
|
64
|
-
|
65
|
-
The schema shows:
|
66
|
-
- Collections (usually 'nodes' and 'edges')
|
67
|
-
- Node types in each collection
|
68
|
-
- Available properties for each node type
|
69
|
-
- Relationship types and their properties
|
70
|
-
|
71
|
-
Examine the schema carefully before writing queries to ensure:
|
72
|
-
- Correct property names
|
73
|
-
- Correct node types
|
74
|
-
- Correct relationship types
|
75
|
-
|
76
|
-
You must be smart about using the right collection names and attributes
|
77
|
-
based on the English description. If you are thinking of using a collection
|
78
|
-
or attribute that does not exist, you are probably on the wrong track,
|
79
|
-
so you should try your best to answer based on existing collections and attributes.
|
80
|
-
DO NOT assume any collections or graphs other than those above.
|
81
|
-
"""
|
82
|
-
|
83
|
-
tool_result_instruction = """
|
84
|
-
REMEMBER:
|
85
|
-
[1] DO NOT FORGET TO USE ONE OF THE AVAILABLE TOOLS TO ANSWER THE USER'S QUERY!!
|
86
|
-
[2] When using a TOOL/FUNCTION, you MUST WAIT for the tool result before continuing
|
87
|
-
with your response. DO NOT MAKE UP RESULTS FROM A TOOL!
|
88
|
-
[3] YOU MUST NOT ANSWER queries from your OWN KNOWLEDGE; ALWAYS RELY ON
|
89
|
-
the result of a TOOL/FUNCTION to compose your response.
|
90
|
-
[4] Use ONLY ONE TOOL/FUNCTION at a TIME!
|
91
|
-
"""
|
92
|
-
# sys msg to use when schema already provided initially,
|
93
|
-
# so agent should not use schema tool
|
94
|
-
SCHEMA_PROVIDED_SYS_MSG = f"""You are a data scientist and expert in Graph Databases,
|
95
|
-
with expertise in answering questions by interacting with an ArangoDB database.
|
96
|
-
|
97
|
-
The schema below describes the ArangoDB database structure,
|
98
|
-
collections (document and edge),
|
99
|
-
and their attribute keys available in your ArangoDB database.
|
100
|
-
|
101
|
-
=== SCHEMA ===
|
102
|
-
{{schema}}
|
103
|
-
=== END SCHEMA ===
|
104
|
-
|
105
|
-
|
106
|
-
To help with the user's question or database update/creation request,
|
107
|
-
you have access to these tools:
|
108
|
-
|
109
|
-
- {aql_retrieval_tool_description}
|
110
|
-
|
111
|
-
- {aql_creation_tool_description}
|
112
|
-
|
113
|
-
|
114
|
-
{tool_result_instruction}
|
115
|
-
"""
|
116
|
-
|
117
|
-
# sys msg to use when schema is not initially provided,
|
118
|
-
# and we want agent to use schema tool to get schema
|
119
|
-
SCHEMA_TOOLS_SYS_MSG = f"""You are a data scientist and expert in
|
120
|
-
Arango Graph Databases,
|
121
|
-
with expertise in answering questions by querying ArangoDB database
|
122
|
-
using the Arango Query Language (AQL).
|
123
|
-
You have access to the following tools:
|
124
|
-
|
125
|
-
- {arango_schema_tool_description}
|
126
|
-
|
127
|
-
- {aql_retrieval_tool_description}
|
128
|
-
|
129
|
-
- {aql_creation_tool_description}
|
130
|
-
|
131
|
-
{tool_result_instruction}
|
132
|
-
"""
|
133
|
-
|
134
|
-
DEFAULT_ARANGO_CHAT_SYSTEM_MESSAGE = f"""
|
135
|
-
{{mode}}
|
136
|
-
|
137
|
-
You do not need to be able to answer a question with just one query.
|
138
|
-
You can make a query, WAIT for the result,
|
139
|
-
THEN make ANOTHER query, WAIT for result,
|
140
|
-
THEN make ANOTHER query, and so on, until you have the answer.
|
141
|
-
|
142
|
-
{aql_query_instructions}
|
143
|
-
|
144
|
-
RETRY-SUGGESTIONS:
|
145
|
-
If you receive a null or other unexpected result,
|
146
|
-
(a) make sure you use the available TOOLs correctly,
|
147
|
-
(b) learn more about the schema using EITHER:
|
148
|
-
- `{arango_schema_tool_name}` tool/function-call to find properties of specific
|
149
|
-
collections or other parts of the schema, OR
|
150
|
-
- `{aql_retrieval_tool_name}` tool/function-call to use AQL queries to
|
151
|
-
find specific parts of the schema.
|
152
|
-
(c) Collection names are CASE-SENSITIVE -- make sure you adhere to the exact
|
153
|
-
collection name you found in the schema.
|
154
|
-
(d) see if you have made an assumption in your AQL query, and try another way,
|
155
|
-
or use `{aql_retrieval_tool_name}` to explore the database contents before
|
156
|
-
submitting your final query.
|
157
|
-
(e) Try APPROXIMATE or PARTIAL MATCHES to strings in the user's query,
|
158
|
-
e.g. user may ask about "Godfather" instead of "The Godfather",
|
159
|
-
or try using CASE-INSENSITIVE MATCHES.
|
160
|
-
|
161
|
-
Start by asking what the user needs help with.
|
162
|
-
|
163
|
-
{tool_result_instruction}
|
164
|
-
|
165
|
-
{aql_retrieval_query_example}
|
166
|
-
"""
|
167
|
-
|
168
|
-
ADDRESSING_INSTRUCTION = """
|
169
|
-
IMPORTANT - Whenever you are NOT writing an AQL query, make sure you address the
|
170
|
-
user using {prefix}User. You MUST use the EXACT syntax {prefix} !!!
|
171
|
-
|
172
|
-
In other words, you ALWAYS EITHER:
|
173
|
-
- write an AQL query using one of the tools,
|
174
|
-
- OR address the user using {prefix}User.
|
175
|
-
|
176
|
-
YOU CANNOT ADDRESS THE USER WHEN USING A TOOL!!
|
177
|
-
"""
|
178
|
-
|
179
|
-
DONE_INSTRUCTION = f"""
|
180
|
-
When you are SURE you have the CORRECT answer to a user's query or request,
|
181
|
-
use the `{done_tool_name}` with `content` set to the answer or result.
|
182
|
-
If you DO NOT think you have the answer to the user's query or request,
|
183
|
-
you SHOULD NOT use the `{done_tool_name}` tool.
|
184
|
-
Instead, you must CONTINUE to improve your queries (tools) to get the correct answer,
|
185
|
-
and finally use the `{done_tool_name}` tool to send the correct answer to the user.
|
186
|
-
"""
|
@@ -1,107 +0,0 @@
|
|
1
|
-
from typing import List, Tuple
|
2
|
-
|
3
|
-
from langroid.agent.tool_message import ToolMessage
|
4
|
-
|
5
|
-
|
6
|
-
class AQLRetrievalTool(ToolMessage):
|
7
|
-
request: str = "aql_retrieval_tool"
|
8
|
-
purpose: str = """
|
9
|
-
To send an <aql_query> in response to a user's request/question,
|
10
|
-
OR to find SCHEMA information,
|
11
|
-
and WAIT for results of the <aql_query> BEFORE continuing with response.
|
12
|
-
You will receive RESULTS from this tool, and ONLY THEN you can continue.
|
13
|
-
"""
|
14
|
-
aql_query: str
|
15
|
-
|
16
|
-
_max_result_tokens = 500
|
17
|
-
_max_retained_tokens = 200
|
18
|
-
|
19
|
-
@classmethod
|
20
|
-
def examples(cls) -> List[ToolMessage | Tuple[str, ToolMessage]]:
|
21
|
-
"""Few-shot examples to include in tool instructions."""
|
22
|
-
return [
|
23
|
-
(
|
24
|
-
"I want to see who Bob's Father is",
|
25
|
-
cls(
|
26
|
-
aql_query="""
|
27
|
-
FOR v, e, p IN 1..1 OUTBOUND 'users/Bob' GRAPH 'family_tree'
|
28
|
-
FILTER p.edges[0].type == 'father'
|
29
|
-
RETURN v
|
30
|
-
"""
|
31
|
-
),
|
32
|
-
),
|
33
|
-
(
|
34
|
-
"I want to know the properties of the Actor node",
|
35
|
-
cls(
|
36
|
-
aql_query="""
|
37
|
-
FOR doc IN Actor
|
38
|
-
LIMIT 1
|
39
|
-
RETURN ATTRIBUTES(doc)
|
40
|
-
"""
|
41
|
-
),
|
42
|
-
),
|
43
|
-
]
|
44
|
-
|
45
|
-
@classmethod
|
46
|
-
def instructions(cls) -> str:
|
47
|
-
return """
|
48
|
-
When using this TOOL/Function-call, you must WAIT to receive the RESULTS
|
49
|
-
of the AQL query, before continuing your response!
|
50
|
-
DO NOT ASSUME YOU KNOW THE RESULTs BEFORE RECEIVING THEM.
|
51
|
-
"""
|
52
|
-
|
53
|
-
|
54
|
-
aql_retrieval_tool_name = AQLRetrievalTool.default_value("request")
|
55
|
-
|
56
|
-
|
57
|
-
class AQLCreationTool(ToolMessage):
|
58
|
-
request: str = "aql_creation_tool"
|
59
|
-
purpose: str = """
|
60
|
-
To send the <aql_query> to create documents/edges in the graph database.
|
61
|
-
IMPORTANT: YOU MUST WAIT FOR THE RESULT OF THE TOOL BEFORE CONTINUING.
|
62
|
-
You will receive RESULTS from this tool, and ONLY THEN you can continue.
|
63
|
-
"""
|
64
|
-
aql_query: str
|
65
|
-
|
66
|
-
@classmethod
|
67
|
-
def examples(cls) -> List[ToolMessage | Tuple[str, ToolMessage]]:
|
68
|
-
"""Few-shot examples to include in tool instructions."""
|
69
|
-
return [
|
70
|
-
(
|
71
|
-
"Create a new document in the collection 'users'",
|
72
|
-
cls(
|
73
|
-
aql_query="""
|
74
|
-
INSERT {
|
75
|
-
"name": "Alice",
|
76
|
-
"age": 30
|
77
|
-
} INTO users
|
78
|
-
"""
|
79
|
-
),
|
80
|
-
),
|
81
|
-
]
|
82
|
-
|
83
|
-
|
84
|
-
aql_creation_tool_name = AQLCreationTool.default_value("request")
|
85
|
-
|
86
|
-
|
87
|
-
class ArangoSchemaTool(ToolMessage):
|
88
|
-
request: str = "arango_schema_tool"
|
89
|
-
purpose: str = """
|
90
|
-
To get the schema of the Arango graph database,
|
91
|
-
or some part of it. Follow these instructions:
|
92
|
-
1. Set <properties> to True to get the properties of the collections,
|
93
|
-
and False if you only want to see the graph structure and get only the
|
94
|
-
from/to relations of the edges.
|
95
|
-
2. Set <collections> to a list of collection names if you want to see,
|
96
|
-
or leave it as None to see all ALL collections.
|
97
|
-
IMPORTANT: YOU MUST WAIT FOR THE RESULT OF THE TOOL BEFORE CONTINUING.
|
98
|
-
You will receive RESULTS from this tool, and ONLY THEN you can continue.
|
99
|
-
"""
|
100
|
-
|
101
|
-
properties: bool = True
|
102
|
-
collections: List[str] | None = None
|
103
|
-
|
104
|
-
_max_result_tokens = 500
|
105
|
-
|
106
|
-
|
107
|
-
arango_schema_tool_name = ArangoSchemaTool.default_value("request")
|
@@ -1,36 +0,0 @@
|
|
1
|
-
from typing import Any, Dict, List
|
2
|
-
|
3
|
-
|
4
|
-
def count_fields(schema: Dict[str, List[Dict[str, Any]]]) -> int:
|
5
|
-
total = 0
|
6
|
-
for coll in schema["Collection Schema"]:
|
7
|
-
# Count all keys in each collection's dict
|
8
|
-
total += len(coll)
|
9
|
-
# Also count properties if they exist
|
10
|
-
props = coll.get(f"{coll['collection_type']}_properties", [])
|
11
|
-
total += len(props)
|
12
|
-
return total
|
13
|
-
|
14
|
-
|
15
|
-
def trim_schema(
|
16
|
-
schema: Dict[str, List[Dict[str, Any]]]
|
17
|
-
) -> Dict[str, List[Dict[str, Any]]]:
|
18
|
-
"""Keep only edge connection info, remove properties and examples"""
|
19
|
-
trimmed: Dict[str, List[Dict[str, Any]]] = {
|
20
|
-
"Graph Schema": schema["Graph Schema"],
|
21
|
-
"Collection Schema": [],
|
22
|
-
}
|
23
|
-
for coll in schema["Collection Schema"]:
|
24
|
-
col_info: Dict[str, Any] = {
|
25
|
-
"collection_name": coll["collection_name"],
|
26
|
-
"collection_type": coll["collection_type"],
|
27
|
-
}
|
28
|
-
if coll["collection_type"] == "edge":
|
29
|
-
# preserve from/to info if present
|
30
|
-
if f"example_{coll['collection_type']}" in coll:
|
31
|
-
example = coll[f"example_{coll['collection_type']}"]
|
32
|
-
if example and "_from" in example:
|
33
|
-
col_info["from_collection"] = example["_from"].split("/")[0]
|
34
|
-
col_info["to_collection"] = example["_to"].split("/")[0]
|
35
|
-
trimmed["Collection Schema"].append(col_info)
|
36
|
-
return trimmed
|