valmar 0.1.0__tar.gz
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.
- valmar-0.1.0/.gitignore +7 -0
- valmar-0.1.0/LICENSE +190 -0
- valmar-0.1.0/PKG-INFO +131 -0
- valmar-0.1.0/README.md +104 -0
- valmar-0.1.0/pyproject.toml +68 -0
- valmar-0.1.0/src/valmar/__init__.py +49 -0
- valmar-0.1.0/src/valmar/client.py +176 -0
- valmar-0.1.0/src/valmar/models.py +189 -0
- valmar-0.1.0/src/valmar/py.typed +1 -0
- valmar-0.1.0/src/valmar/tools.py +127 -0
valmar-0.1.0/.gitignore
ADDED
valmar-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
https://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Valmar
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
valmar-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: valmar
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the Valmar platform
|
|
5
|
+
Project-URL: Homepage, https://docs.getvalmar.com
|
|
6
|
+
Project-URL: Documentation, https://docs.getvalmar.com
|
|
7
|
+
Project-URL: Source, https://github.com/TheValmarAI/valmar-python
|
|
8
|
+
Author: Valmar
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,enterprise-context,knowledge,sdk,valmar
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: httpx>=0.27
|
|
23
|
+
Requires-Dist: pydantic>=2.0
|
|
24
|
+
Provides-Extra: ai
|
|
25
|
+
Requires-Dist: pydantic-ai>=0.1; extra == 'ai'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# valmar
|
|
29
|
+
|
|
30
|
+
Python SDK for the Valmar platform.
|
|
31
|
+
|
|
32
|
+
Documentation: https://docs.getvalmar.com
|
|
33
|
+
|
|
34
|
+
Source: https://github.com/TheValmarAI/valmar-python
|
|
35
|
+
|
|
36
|
+
License: Apache-2.0
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
uv add valmar
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quick start
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from valmar import Valmar
|
|
48
|
+
|
|
49
|
+
client = Valmar(
|
|
50
|
+
api_key="valmr_proj_sk_...",
|
|
51
|
+
base_url="https://your-valmar-deployment.example.com",
|
|
52
|
+
organization_id="your-org-id",
|
|
53
|
+
project_id="your-project-id",
|
|
54
|
+
)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`base_url` is required because Valmar is deployed per customer. Use the base URL for your own Valmar deployment.
|
|
58
|
+
|
|
59
|
+
## Search knowledge
|
|
60
|
+
|
|
61
|
+
Find relevant saved knowledge across the configured project.
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
results = client.knowledge.search("deployment process")
|
|
65
|
+
|
|
66
|
+
for item in results.items:
|
|
67
|
+
print(f"{item.title} ({item.confidence})")
|
|
68
|
+
print(item.content_md)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Create a knowledge request
|
|
72
|
+
|
|
73
|
+
Create a knowledge request that gets routed to the right people in your organization.
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
handle = client.knowledge_requests.create(
|
|
77
|
+
"How do we handle database migrations in production?",
|
|
78
|
+
background_context="Planning a schema change for the orders table",
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
print(f"Request created: {handle.knowledge_request_id}")
|
|
82
|
+
print(f"Status: {handle.status}")
|
|
83
|
+
|
|
84
|
+
request = client.knowledge_requests.get(handle.knowledge_request_id)
|
|
85
|
+
if request.status == "completed":
|
|
86
|
+
print(request.result_summary)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## List and import people
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from valmar import CreatePersonInput
|
|
93
|
+
|
|
94
|
+
people = client.people.list()
|
|
95
|
+
|
|
96
|
+
result = client.people.import_bulk(
|
|
97
|
+
[
|
|
98
|
+
CreatePersonInput(
|
|
99
|
+
email="ada@example.com",
|
|
100
|
+
display_name="Ada Lovelace",
|
|
101
|
+
timezone="UTC",
|
|
102
|
+
title="Principal Engineer",
|
|
103
|
+
)
|
|
104
|
+
]
|
|
105
|
+
)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Context manager
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
with Valmar(
|
|
112
|
+
api_key="valmr_proj_sk_...",
|
|
113
|
+
base_url="https://your-valmar-deployment.example.com",
|
|
114
|
+
organization_id="your-org-id",
|
|
115
|
+
project_id="your-project-id",
|
|
116
|
+
) as client:
|
|
117
|
+
results = client.knowledge.search("onboarding process")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Error handling
|
|
121
|
+
|
|
122
|
+
The SDK raises `httpx.HTTPStatusError` for non-2xx responses.
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
import httpx
|
|
126
|
+
|
|
127
|
+
try:
|
|
128
|
+
client.knowledge.search("test")
|
|
129
|
+
except httpx.HTTPStatusError as e:
|
|
130
|
+
print(f"API error {e.response.status_code}: {e.response.text}")
|
|
131
|
+
```
|
valmar-0.1.0/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# valmar
|
|
2
|
+
|
|
3
|
+
Python SDK for the Valmar platform.
|
|
4
|
+
|
|
5
|
+
Documentation: https://docs.getvalmar.com
|
|
6
|
+
|
|
7
|
+
Source: https://github.com/TheValmarAI/valmar-python
|
|
8
|
+
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
uv add valmar
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from valmar import Valmar
|
|
21
|
+
|
|
22
|
+
client = Valmar(
|
|
23
|
+
api_key="valmr_proj_sk_...",
|
|
24
|
+
base_url="https://your-valmar-deployment.example.com",
|
|
25
|
+
organization_id="your-org-id",
|
|
26
|
+
project_id="your-project-id",
|
|
27
|
+
)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`base_url` is required because Valmar is deployed per customer. Use the base URL for your own Valmar deployment.
|
|
31
|
+
|
|
32
|
+
## Search knowledge
|
|
33
|
+
|
|
34
|
+
Find relevant saved knowledge across the configured project.
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
results = client.knowledge.search("deployment process")
|
|
38
|
+
|
|
39
|
+
for item in results.items:
|
|
40
|
+
print(f"{item.title} ({item.confidence})")
|
|
41
|
+
print(item.content_md)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Create a knowledge request
|
|
45
|
+
|
|
46
|
+
Create a knowledge request that gets routed to the right people in your organization.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
handle = client.knowledge_requests.create(
|
|
50
|
+
"How do we handle database migrations in production?",
|
|
51
|
+
background_context="Planning a schema change for the orders table",
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
print(f"Request created: {handle.knowledge_request_id}")
|
|
55
|
+
print(f"Status: {handle.status}")
|
|
56
|
+
|
|
57
|
+
request = client.knowledge_requests.get(handle.knowledge_request_id)
|
|
58
|
+
if request.status == "completed":
|
|
59
|
+
print(request.result_summary)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## List and import people
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from valmar import CreatePersonInput
|
|
66
|
+
|
|
67
|
+
people = client.people.list()
|
|
68
|
+
|
|
69
|
+
result = client.people.import_bulk(
|
|
70
|
+
[
|
|
71
|
+
CreatePersonInput(
|
|
72
|
+
email="ada@example.com",
|
|
73
|
+
display_name="Ada Lovelace",
|
|
74
|
+
timezone="UTC",
|
|
75
|
+
title="Principal Engineer",
|
|
76
|
+
)
|
|
77
|
+
]
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Context manager
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
with Valmar(
|
|
85
|
+
api_key="valmr_proj_sk_...",
|
|
86
|
+
base_url="https://your-valmar-deployment.example.com",
|
|
87
|
+
organization_id="your-org-id",
|
|
88
|
+
project_id="your-project-id",
|
|
89
|
+
) as client:
|
|
90
|
+
results = client.knowledge.search("onboarding process")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Error handling
|
|
94
|
+
|
|
95
|
+
The SDK raises `httpx.HTTPStatusError` for non-2xx responses.
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
import httpx
|
|
99
|
+
|
|
100
|
+
try:
|
|
101
|
+
client.knowledge.search("test")
|
|
102
|
+
except httpx.HTTPStatusError as e:
|
|
103
|
+
print(f"API error {e.response.status_code}: {e.response.text}")
|
|
104
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "valmar"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Python SDK for the Valmar platform"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
authors = [
|
|
8
|
+
{ name = "Valmar" },
|
|
9
|
+
]
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
keywords = ["valmar", "sdk", "agents", "enterprise-context", "knowledge"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: Apache Software License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"httpx>=0.27",
|
|
26
|
+
"pydantic>=2.0",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://docs.getvalmar.com"
|
|
31
|
+
Documentation = "https://docs.getvalmar.com"
|
|
32
|
+
Source = "https://github.com/TheValmarAI/valmar-python"
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
ai = ["pydantic-ai>=0.1"]
|
|
36
|
+
|
|
37
|
+
[dependency-groups]
|
|
38
|
+
dev = [
|
|
39
|
+
"pytest>=8.0",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[build-system]
|
|
43
|
+
requires = ["hatchling"]
|
|
44
|
+
build-backend = "hatchling.build"
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build]
|
|
47
|
+
ignore-vcs = true
|
|
48
|
+
only-packages = true
|
|
49
|
+
|
|
50
|
+
[tool.hatch.build.targets.sdist]
|
|
51
|
+
only-include = [
|
|
52
|
+
"/README.md",
|
|
53
|
+
"/LICENSE",
|
|
54
|
+
"/pyproject.toml",
|
|
55
|
+
"/src/valmar",
|
|
56
|
+
]
|
|
57
|
+
exclude = [
|
|
58
|
+
"**/__pycache__",
|
|
59
|
+
"**/*.pyc",
|
|
60
|
+
"/.gitignore",
|
|
61
|
+
"/.pytest_cache",
|
|
62
|
+
"/.venv",
|
|
63
|
+
"/tests",
|
|
64
|
+
"/uv.lock",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
[tool.hatch.build.targets.wheel]
|
|
68
|
+
packages = ["src/valmar"]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Valmar Python SDK."""
|
|
2
|
+
|
|
3
|
+
from valmar.client import Valmar
|
|
4
|
+
from valmar.models import (
|
|
5
|
+
CreateKnowledgeRequestInput,
|
|
6
|
+
CreatePersonInput,
|
|
7
|
+
ImportPeopleInput,
|
|
8
|
+
ImportPeopleResult,
|
|
9
|
+
ImportPersonResult,
|
|
10
|
+
KnowledgeItem,
|
|
11
|
+
KnowledgeItemProvenance,
|
|
12
|
+
KnowledgeItemType,
|
|
13
|
+
KnowledgeRequest,
|
|
14
|
+
KnowledgeRequestAnswer,
|
|
15
|
+
KnowledgeRequestHandle,
|
|
16
|
+
KnowledgeRequestListItem,
|
|
17
|
+
KnowledgeRequestResolutionStatus,
|
|
18
|
+
KnowledgeRequestStatus,
|
|
19
|
+
KnowledgeSearchResult,
|
|
20
|
+
Person,
|
|
21
|
+
ProjectRole,
|
|
22
|
+
ReviewStatus,
|
|
23
|
+
SearchKnowledgeInput,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"Valmar",
|
|
28
|
+
"CreateKnowledgeRequestInput",
|
|
29
|
+
"CreatePersonInput",
|
|
30
|
+
"ImportPeopleInput",
|
|
31
|
+
"ImportPeopleResult",
|
|
32
|
+
"ImportPersonResult",
|
|
33
|
+
"KnowledgeItem",
|
|
34
|
+
"KnowledgeItemProvenance",
|
|
35
|
+
"KnowledgeItemType",
|
|
36
|
+
"KnowledgeRequest",
|
|
37
|
+
"KnowledgeRequestAnswer",
|
|
38
|
+
"KnowledgeRequestHandle",
|
|
39
|
+
"KnowledgeRequestListItem",
|
|
40
|
+
"KnowledgeRequestResolutionStatus",
|
|
41
|
+
"KnowledgeRequestStatus",
|
|
42
|
+
"KnowledgeSearchResult",
|
|
43
|
+
"Person",
|
|
44
|
+
"ProjectRole",
|
|
45
|
+
"ReviewStatus",
|
|
46
|
+
"SearchKnowledgeInput",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""Valmar Python SDK client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
from uuid import UUID
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
|
|
10
|
+
from valmar.models import (
|
|
11
|
+
CreateKnowledgeRequestInput,
|
|
12
|
+
CreatePersonInput,
|
|
13
|
+
ImportPeopleInput,
|
|
14
|
+
ImportPeopleResult,
|
|
15
|
+
KnowledgeItemType,
|
|
16
|
+
KnowledgeRequest,
|
|
17
|
+
KnowledgeRequestHandle,
|
|
18
|
+
KnowledgeRequestListItem,
|
|
19
|
+
KnowledgeSearchResult,
|
|
20
|
+
Person,
|
|
21
|
+
SearchKnowledgeInput,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
DEFAULT_TIMEOUT = 30.0
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class _Resource:
|
|
28
|
+
def __init__(self, client: Valmar) -> None:
|
|
29
|
+
self._client = client
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def _http(self) -> httpx.Client:
|
|
33
|
+
return self._client._http
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def _organization_id(self) -> UUID | None:
|
|
37
|
+
return self._client.organization_id
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def _project_id(self) -> UUID | None:
|
|
41
|
+
return self._client.project_id
|
|
42
|
+
|
|
43
|
+
def _require_organization_id(self) -> UUID:
|
|
44
|
+
if self._organization_id is None:
|
|
45
|
+
raise ValueError("organization_id must be set on the client for this operation.")
|
|
46
|
+
return self._organization_id
|
|
47
|
+
|
|
48
|
+
def _require_project_id(self) -> UUID:
|
|
49
|
+
if self._project_id is None:
|
|
50
|
+
raise ValueError("project_id must be set on the client for this operation.")
|
|
51
|
+
return self._project_id
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class KnowledgeResource(_Resource):
|
|
55
|
+
"""Search project-scoped knowledge saved by Valmar."""
|
|
56
|
+
|
|
57
|
+
def search(
|
|
58
|
+
self,
|
|
59
|
+
query: str = "",
|
|
60
|
+
*,
|
|
61
|
+
limit: int = 10,
|
|
62
|
+
types: list[KnowledgeItemType | str] | None = None,
|
|
63
|
+
related_member_ids: list[UUID | str] | None = None,
|
|
64
|
+
) -> KnowledgeSearchResult:
|
|
65
|
+
payload = SearchKnowledgeInput(
|
|
66
|
+
organization_id=self._require_organization_id(),
|
|
67
|
+
project_id=self._require_project_id(),
|
|
68
|
+
query=query,
|
|
69
|
+
limit=limit,
|
|
70
|
+
types=[KnowledgeItemType(item) for item in (types or [])],
|
|
71
|
+
related_member_ids=[UUID(str(item)) for item in (related_member_ids or [])],
|
|
72
|
+
)
|
|
73
|
+
response = self._http.post("/api/knowledge/search", json=payload.model_dump(mode="json"))
|
|
74
|
+
response.raise_for_status()
|
|
75
|
+
return KnowledgeSearchResult.model_validate(response.json())
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class KnowledgeRequestsResource(_Resource):
|
|
79
|
+
"""Create and inspect human-routed knowledge requests."""
|
|
80
|
+
|
|
81
|
+
def create(
|
|
82
|
+
self,
|
|
83
|
+
question: str,
|
|
84
|
+
*,
|
|
85
|
+
already_tried: str | None = None,
|
|
86
|
+
background_context: str | None = None,
|
|
87
|
+
requesting_application: str = "valmar-sdk-python",
|
|
88
|
+
source_agent_config_id: UUID | str | None = None,
|
|
89
|
+
) -> KnowledgeRequestHandle:
|
|
90
|
+
payload = CreateKnowledgeRequestInput(
|
|
91
|
+
project_id=self._require_project_id(),
|
|
92
|
+
requesting_application=requesting_application,
|
|
93
|
+
question=question,
|
|
94
|
+
already_tried=already_tried,
|
|
95
|
+
background_context=background_context,
|
|
96
|
+
source_agent_config_id=(
|
|
97
|
+
UUID(str(source_agent_config_id)) if source_agent_config_id is not None else None
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
response = self._http.post(
|
|
101
|
+
"/api/knowledge/requests",
|
|
102
|
+
json=payload.model_dump(mode="json"),
|
|
103
|
+
)
|
|
104
|
+
response.raise_for_status()
|
|
105
|
+
return KnowledgeRequestHandle.model_validate(response.json())
|
|
106
|
+
|
|
107
|
+
def get(self, knowledge_request_id: UUID | str) -> KnowledgeRequest:
|
|
108
|
+
response = self._http.get(f"/api/knowledge/requests/{knowledge_request_id}")
|
|
109
|
+
response.raise_for_status()
|
|
110
|
+
return KnowledgeRequest.model_validate(response.json())
|
|
111
|
+
|
|
112
|
+
def list(self) -> list[KnowledgeRequestListItem]:
|
|
113
|
+
response = self._http.get(
|
|
114
|
+
f"/api/projects/{self._require_project_id()}/knowledge-requests",
|
|
115
|
+
)
|
|
116
|
+
response.raise_for_status()
|
|
117
|
+
return [KnowledgeRequestListItem.model_validate(item) for item in response.json()]
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class PeopleResource(_Resource):
|
|
121
|
+
"""Manage organization people that Valmar may contact."""
|
|
122
|
+
|
|
123
|
+
def list(self) -> list[Person]:
|
|
124
|
+
response = self._http.get(f"/api/organizations/{self._require_organization_id()}/people")
|
|
125
|
+
response.raise_for_status()
|
|
126
|
+
return [Person.model_validate(item) for item in response.json()]
|
|
127
|
+
|
|
128
|
+
def import_bulk(self, people: list[CreatePersonInput]) -> ImportPeopleResult:
|
|
129
|
+
payload = ImportPeopleInput(people=people)
|
|
130
|
+
response = self._http.post(
|
|
131
|
+
f"/api/organizations/{self._require_organization_id()}/people/import",
|
|
132
|
+
json=payload.model_dump(mode="json"),
|
|
133
|
+
)
|
|
134
|
+
response.raise_for_status()
|
|
135
|
+
return ImportPeopleResult.model_validate(response.json())
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class Valmar:
|
|
139
|
+
"""Small HTTP client for the Valmar REST API."""
|
|
140
|
+
|
|
141
|
+
def __init__(
|
|
142
|
+
self,
|
|
143
|
+
api_key: str,
|
|
144
|
+
*,
|
|
145
|
+
base_url: str,
|
|
146
|
+
organization_id: UUID | str | None = None,
|
|
147
|
+
project_id: UUID | str | None = None,
|
|
148
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
149
|
+
) -> None:
|
|
150
|
+
self.api_key = api_key
|
|
151
|
+
self.base_url = base_url.rstrip("/")
|
|
152
|
+
self.organization_id: UUID | None = UUID(str(organization_id)) if organization_id else None
|
|
153
|
+
self.project_id: UUID | None = UUID(str(project_id)) if project_id else None
|
|
154
|
+
|
|
155
|
+
self._http = httpx.Client(
|
|
156
|
+
base_url=self.base_url,
|
|
157
|
+
headers={
|
|
158
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
159
|
+
"Content-Type": "application/json",
|
|
160
|
+
"User-Agent": "valmar-sdk-python/0.1.0",
|
|
161
|
+
},
|
|
162
|
+
timeout=timeout,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
self.knowledge = KnowledgeResource(self)
|
|
166
|
+
self.knowledge_requests = KnowledgeRequestsResource(self)
|
|
167
|
+
self.people = PeopleResource(self)
|
|
168
|
+
|
|
169
|
+
def close(self) -> None:
|
|
170
|
+
self._http.close()
|
|
171
|
+
|
|
172
|
+
def __enter__(self) -> Valmar:
|
|
173
|
+
return self
|
|
174
|
+
|
|
175
|
+
def __exit__(self, *args: Any) -> None:
|
|
176
|
+
self.close()
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Pydantic models for the Valmar Python SDK."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from enum import StrEnum
|
|
7
|
+
from uuid import UUID
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ValmarModel(BaseModel):
|
|
13
|
+
model_config = ConfigDict(populate_by_name=True)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class KnowledgeRequestStatus(StrEnum):
|
|
17
|
+
PENDING = "pending"
|
|
18
|
+
DEFERRED = "deferred"
|
|
19
|
+
WAITING_FOR_REPLY = "waiting_for_reply"
|
|
20
|
+
COMPLETED = "completed"
|
|
21
|
+
TIMED_OUT = "timed_out"
|
|
22
|
+
FAILED = "failed"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class KnowledgeRequestResolutionStatus(StrEnum):
|
|
26
|
+
RESOLVED = "resolved"
|
|
27
|
+
PARTIAL_RESOLUTION = "partial_resolution"
|
|
28
|
+
NOT_RESOLVED = "not_resolved"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class KnowledgeItemType(StrEnum):
|
|
32
|
+
TEXT = "text"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ReviewStatus(StrEnum):
|
|
36
|
+
AUTO_ACCEPTED = "auto_accepted"
|
|
37
|
+
NEEDS_REVIEW = "needs_review"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ProjectRole(StrEnum):
|
|
41
|
+
PROJECT_ADMIN = "project_admin"
|
|
42
|
+
PROJECT_MEMBER = "project_member"
|
|
43
|
+
SERVICE = "service"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class KnowledgeItemProvenance(ValmarModel):
|
|
47
|
+
source_thread_id: UUID | None = None
|
|
48
|
+
source_member_id: UUID | None = None
|
|
49
|
+
source_agent_run_id: UUID | None = None
|
|
50
|
+
source_knowledge_request_id: UUID | None = Field(
|
|
51
|
+
default=None,
|
|
52
|
+
validation_alias="source_knowledge_request_id",
|
|
53
|
+
serialization_alias="source_knowledge_request_id",
|
|
54
|
+
)
|
|
55
|
+
source_message_id: UUID | None = None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class KnowledgeRequestAnswer(ValmarModel):
|
|
59
|
+
status: KnowledgeRequestResolutionStatus
|
|
60
|
+
answer_text: str
|
|
61
|
+
answer_knowledge_items: list[UUID] = Field(
|
|
62
|
+
default_factory=list,
|
|
63
|
+
validation_alias="answer_knowledge_items",
|
|
64
|
+
serialization_alias="answer_knowledge_items",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class KnowledgeItem(ValmarModel):
|
|
69
|
+
id: UUID
|
|
70
|
+
created_at: datetime
|
|
71
|
+
updated_at: datetime
|
|
72
|
+
organization_id: UUID
|
|
73
|
+
project_id: UUID
|
|
74
|
+
knowledge_request_id: UUID | None = Field(
|
|
75
|
+
default=None,
|
|
76
|
+
validation_alias="knowledge_request_id",
|
|
77
|
+
serialization_alias="knowledge_request_id",
|
|
78
|
+
)
|
|
79
|
+
type: KnowledgeItemType
|
|
80
|
+
title: str
|
|
81
|
+
content_md: str
|
|
82
|
+
provenance: KnowledgeItemProvenance
|
|
83
|
+
confidence: float = 0.65
|
|
84
|
+
review_status: ReviewStatus = ReviewStatus.AUTO_ACCEPTED
|
|
85
|
+
related_member_ids: list[UUID] = Field(default_factory=list)
|
|
86
|
+
related_twin_node_ids: list[UUID] = Field(default_factory=list)
|
|
87
|
+
tags: list[str] = Field(default_factory=list)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class KnowledgeSearchResult(ValmarModel):
|
|
91
|
+
items: list[KnowledgeItem] = Field(default_factory=list)
|
|
92
|
+
total_count: int = 0
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class KnowledgeRequest(ValmarModel):
|
|
96
|
+
id: UUID
|
|
97
|
+
created_at: datetime
|
|
98
|
+
updated_at: datetime
|
|
99
|
+
organization_id: UUID
|
|
100
|
+
project_id: UUID
|
|
101
|
+
requesting_application: str
|
|
102
|
+
question: str
|
|
103
|
+
already_tried: str | None = None
|
|
104
|
+
background_context: str | None = None
|
|
105
|
+
candidate_member_ids: list[UUID] = Field(default_factory=list)
|
|
106
|
+
status: KnowledgeRequestStatus = KnowledgeRequestStatus.PENDING
|
|
107
|
+
source_agent_config_id: UUID | None = None
|
|
108
|
+
response_deadline_at: datetime | None = None
|
|
109
|
+
result_summary: str | None = None
|
|
110
|
+
answer: KnowledgeRequestAnswer | None = None
|
|
111
|
+
resolved_thread_id: UUID | None = None
|
|
112
|
+
created_by_actor_id: str | None = None
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class KnowledgeRequestListItem(ValmarModel):
|
|
116
|
+
id: UUID
|
|
117
|
+
project_id: UUID
|
|
118
|
+
requesting_application: str
|
|
119
|
+
question: str
|
|
120
|
+
status: KnowledgeRequestStatus
|
|
121
|
+
result_summary: str | None = None
|
|
122
|
+
created_at: datetime
|
|
123
|
+
assigned_member_id: UUID | None = None
|
|
124
|
+
assigned_member_display_name: str | None = None
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class KnowledgeRequestHandle(ValmarModel):
|
|
128
|
+
knowledge_request_id: UUID = Field(
|
|
129
|
+
validation_alias="knowledge_request_id",
|
|
130
|
+
serialization_alias="knowledge_request_id",
|
|
131
|
+
)
|
|
132
|
+
status: KnowledgeRequestStatus
|
|
133
|
+
resource_uri: str
|
|
134
|
+
message: str
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class Person(ValmarModel):
|
|
138
|
+
id: UUID
|
|
139
|
+
created_at: datetime
|
|
140
|
+
updated_at: datetime
|
|
141
|
+
organization_id: UUID
|
|
142
|
+
email: str
|
|
143
|
+
display_name: str
|
|
144
|
+
timezone: str = "UTC"
|
|
145
|
+
title: str | None = None
|
|
146
|
+
description_md: str = ""
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class CreateKnowledgeRequestInput(ValmarModel):
|
|
150
|
+
project_id: UUID
|
|
151
|
+
requesting_application: str
|
|
152
|
+
question: str
|
|
153
|
+
already_tried: str | None = None
|
|
154
|
+
background_context: str | None = None
|
|
155
|
+
source_agent_config_id: UUID | None = None
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class SearchKnowledgeInput(ValmarModel):
|
|
159
|
+
organization_id: UUID
|
|
160
|
+
project_id: UUID
|
|
161
|
+
query: str = ""
|
|
162
|
+
types: list[KnowledgeItemType] = Field(default_factory=list)
|
|
163
|
+
related_member_ids: list[UUID] = Field(default_factory=list)
|
|
164
|
+
limit: int = Field(default=10, ge=1, le=100)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class CreatePersonInput(ValmarModel):
|
|
168
|
+
email: str
|
|
169
|
+
display_name: str
|
|
170
|
+
timezone: str = "UTC"
|
|
171
|
+
title: str | None = None
|
|
172
|
+
description_md: str = ""
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class ImportPeopleInput(ValmarModel):
|
|
176
|
+
people: list[CreatePersonInput]
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class ImportPersonResult(ValmarModel):
|
|
180
|
+
email: str
|
|
181
|
+
status: str
|
|
182
|
+
member_id: UUID | None = None
|
|
183
|
+
error: str | None = None
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
class ImportPeopleResult(ValmarModel):
|
|
187
|
+
created: list[ImportPersonResult] = Field(default_factory=list)
|
|
188
|
+
skipped: list[ImportPersonResult] = Field(default_factory=list)
|
|
189
|
+
errors: list[ImportPersonResult] = Field(default_factory=list)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Pydantic AI tool integration for Valmar.
|
|
2
|
+
|
|
3
|
+
Provides a ready-made tool function that AI agents can call to retrieve
|
|
4
|
+
organizational context via the Valmar API. Install with::
|
|
5
|
+
|
|
6
|
+
uv add "valmar[ai]"
|
|
7
|
+
|
|
8
|
+
Usage with pydantic-ai::
|
|
9
|
+
|
|
10
|
+
from pydantic_ai import Agent
|
|
11
|
+
from valmar.tools import valmar_knowledge_tool
|
|
12
|
+
|
|
13
|
+
tool = valmar_knowledge_tool(
|
|
14
|
+
api_key="valmr_proj_sk_...",
|
|
15
|
+
base_url="https://your-valmar-deployment.example.com",
|
|
16
|
+
organization_id="...",
|
|
17
|
+
project_id="...",
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
agent = Agent("openai:gpt-4o", tools=[tool])
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
from typing import Any
|
|
26
|
+
from uuid import UUID
|
|
27
|
+
|
|
28
|
+
from valmar.client import Valmar
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def valmar_knowledge_tool(
|
|
32
|
+
api_key: str,
|
|
33
|
+
*,
|
|
34
|
+
base_url: str,
|
|
35
|
+
organization_id: UUID | str | None = None,
|
|
36
|
+
project_id: UUID | str | None = None,
|
|
37
|
+
requesting_application: str = "pydantic-ai-agent",
|
|
38
|
+
search_threshold: int = 3,
|
|
39
|
+
) -> Any:
|
|
40
|
+
"""Return a Pydantic AI tool function for retrieving Valmar knowledge.
|
|
41
|
+
|
|
42
|
+
The tool first searches existing knowledge. If fewer than ``search_threshold``
|
|
43
|
+
results are found, it falls back to creating a knowledge request.
|
|
44
|
+
|
|
45
|
+
Parameters
|
|
46
|
+
----------
|
|
47
|
+
api_key:
|
|
48
|
+
Valmar project API key (``valmr_proj_sk_...``).
|
|
49
|
+
base_url:
|
|
50
|
+
Base URL of the Valmar API.
|
|
51
|
+
organization_id:
|
|
52
|
+
Organization UUID (required for search operations).
|
|
53
|
+
project_id:
|
|
54
|
+
Project UUID (required for context gather operations).
|
|
55
|
+
requesting_application:
|
|
56
|
+
Application name passed to context-gather requests.
|
|
57
|
+
search_threshold:
|
|
58
|
+
Minimum number of search results required before the tool skips
|
|
59
|
+
the fallback gather step.
|
|
60
|
+
|
|
61
|
+
Returns
|
|
62
|
+
-------
|
|
63
|
+
A callable compatible with ``pydantic_ai.Tool``.
|
|
64
|
+
"""
|
|
65
|
+
try:
|
|
66
|
+
from pydantic_ai import Tool
|
|
67
|
+
except ImportError as exc:
|
|
68
|
+
raise ImportError(
|
|
69
|
+
"pydantic-ai is required for tool integration. "
|
|
70
|
+
'Install it with: uv add "valmar[ai]"'
|
|
71
|
+
) from exc
|
|
72
|
+
|
|
73
|
+
client = Valmar(
|
|
74
|
+
api_key=api_key,
|
|
75
|
+
base_url=base_url,
|
|
76
|
+
organization_id=organization_id,
|
|
77
|
+
project_id=project_id,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
async def search_valmar_knowledge(question: str) -> str:
|
|
81
|
+
"""Search Valmar knowledge for an existing answer.
|
|
82
|
+
|
|
83
|
+
If insufficient results are found, a knowledge request is created to
|
|
84
|
+
collect the information from team members.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
question: The question or topic to look up in the knowledge base.
|
|
88
|
+
"""
|
|
89
|
+
# Step 1: search existing knowledge
|
|
90
|
+
search_result = client.knowledge.search(question, limit=10)
|
|
91
|
+
|
|
92
|
+
if len(search_result.items) >= search_threshold:
|
|
93
|
+
parts = []
|
|
94
|
+
for item in search_result.items:
|
|
95
|
+
parts.append(f"## {item.title}\n{item.content_md}")
|
|
96
|
+
return "\n\n---\n\n".join(parts)
|
|
97
|
+
|
|
98
|
+
# Step 2: fall back to context gather if project_id is available
|
|
99
|
+
if client.project_id is not None:
|
|
100
|
+
handle = client.knowledge_requests.create(
|
|
101
|
+
question,
|
|
102
|
+
requesting_application=requesting_application,
|
|
103
|
+
)
|
|
104
|
+
# Include any search results we did find
|
|
105
|
+
existing = ""
|
|
106
|
+
if search_result.items:
|
|
107
|
+
snippets = [f"- {item.title}: {item.content_md[:200]}" for item in search_result.items]
|
|
108
|
+
existing = "Existing partial results:\n" + "\n".join(snippets) + "\n\n"
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
f"{existing}"
|
|
112
|
+
f"A knowledge request has been created "
|
|
113
|
+
f"(ID: {handle.knowledge_request_id}, status: {handle.status}). "
|
|
114
|
+
f"Valmar will reach out to team members to collect this information. "
|
|
115
|
+
f"You can check the status later with the request ID."
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# No project_id, just return what we have
|
|
119
|
+
if search_result.items:
|
|
120
|
+
parts = []
|
|
121
|
+
for item in search_result.items:
|
|
122
|
+
parts.append(f"## {item.title}\n{item.content_md}")
|
|
123
|
+
return "\n\n---\n\n".join(parts)
|
|
124
|
+
|
|
125
|
+
return "No relevant context found in the knowledge base."
|
|
126
|
+
|
|
127
|
+
return Tool(search_valmar_knowledge, name="valmar_knowledge")
|