Skip to content

Commit 7df706f

Browse files
committed
docs: update readme
feat: export tools
1 parent ec488d2 commit 7df706f

File tree

5 files changed

+76
-9
lines changed

5 files changed

+76
-9
lines changed

src/rai_whoami/README.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ To generate the system prompt from your documentation directory:
4040
python src/rai_whoami/rai_whoami/build_whoami.py documentation_dir [--output_dir output_dir] [--build-vector-db]
4141
```
4242

43+
Generated files will be saved in the `output_dir / generated directory` or `documentation_dir / generated` if not specified.
44+
4345
---
4446

4547
## Using with ROS2 and ReActAgent
@@ -51,16 +53,66 @@ from rai_whoami import EmbodimentInfo
5153
from rai.agents import ReActAgent, wait_for_shutdown
5254
from rai.communication.ros2 import ROS2HRIConnector
5355

54-
info = EmbodimentInfo.from_directory("path/to/documentation_dir/")
56+
info = EmbodimentInfo.from_directory("output_dir/")
5557
system_prompt = info.to_langchain() # Convert EmbodimentInfo to a system prompt
5658

59+
# example usage with langchain runnable
60+
from rai.agents.langchain import create_react_runnable
61+
62+
react_agent = create_react_runnable(
63+
tools=[],
64+
system_prompt=system_prompt
65+
)
66+
67+
# example usage with RAI Agent
5768
connector = ROS2HRIConnector()
5869
agent = ReActAgent(
59-
target_connectors={"ros2": connector},
70+
target_connectors={"/to_human": connector},
6071
system_prompt=system_prompt,
6172
)
6273

6374
agent.run()
6475
connector.register_callback("/from_human", agent)
6576
wait_for_shutdown([agent])
6677
```
78+
79+
## Using generated Vector Database
80+
81+
rai whoami provides a langchain tool to query the generated vector database. There are a couple of ways to use it:
82+
83+
1. Through a langchain runnable
84+
85+
```python
86+
from langchain_core.messages import HumanMessage
87+
from rai_whoami.tools import QueryDatabaseTool
88+
from rai.agents.langchain import create_react_runnable
89+
90+
query_tool = QueryDatabaseTool(root_dir="output_dir/generated")
91+
92+
react_agent = create_react_runnable(tools=[query_tool])
93+
print(
94+
react_agent.invoke(
95+
{"messages": [HumanMessage(content="Check the db for Robot's name")]}
96+
)
97+
)
98+
```
99+
100+
2. Through a RAI Agent
101+
102+
```python
103+
from rai.agents import ReActAgent, wait_for_shutdown
104+
from rai.communication.ros2 import ROS2HRIConnector
105+
106+
from rai_whoami.tools import QueryDatabaseTool
107+
108+
query_tool = QueryDatabaseTool(root_dir="output_dir/generated")
109+
110+
connector = ROS2HRIConnector()
111+
agent = ReActAgent(
112+
target_connectors={"/to_human": connector}, system_prompt="", tools=[query_tool]
113+
)
114+
agent.run()
115+
connector.register_callback("/from_human", agent)
116+
wait_for_shutdown([agent])
117+
118+
```

src/rai_whoami/rai_whoami/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
from .models import EmbodimentInfo, EmbodimentSource
1616
from .pipeline import Pipeline, PipelineBuilder
1717
from .processors import get_default_postprocessors, get_default_preprocessors
18+
from .tools import QueryDatabaseTool
1819

1920
__all__ = [
2021
"EmbodimentInfo",
2122
"EmbodimentSource",
2223
"Pipeline",
2324
"PipelineBuilder",
25+
"QueryDatabaseTool",
2426
"get_default_postprocessors",
2527
"get_default_preprocessors",
2628
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (C) 2025 Robotec.AI
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from rai_whoami.tools.vdb_client import QueryDatabaseTool
16+
17+
__all__ = ["QueryDatabaseTool"]

src/rai_whoami/rai_whoami/tools/vdb_client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ def __init__(self, **kwargs: Any):
6060
from langchain_community.vectorstores import FAISS
6161

6262
if self.embeddings_model is None:
63-
embeddings_kwargs = json.load(
64-
open(Path(self.root_dir) / "embeddings_kwargs.json")
65-
)
63+
vdb_kwargs = json.load(open(Path(self.root_dir) / "vdb_kwargs.json"))
6664
self.embeddings_model = initialize_embeddings(
67-
embeddings_kwargs["class"], **embeddings_kwargs
65+
vdb_kwargs["embeddings"]["class"], **vdb_kwargs
6866
)
6967

7068
self.vdb_client = FAISS.load_local(

src/rai_whoami/rai_whoami/vector_db/builder.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,4 @@ def _build(self, data: EmbodimentSource) -> VectorStore:
5252
"""
5353

5454
def dump_model_kwargs(self):
55-
(self.root_dir / "embeddings_kwargs.json").write_text(
56-
json.dumps(self.model_kwargs)
57-
)
55+
(self.root_dir / "vdb_kwargs.json").write_text(json.dumps(self.model_kwargs))

0 commit comments

Comments
 (0)