lollms-client 0.25.5__py3-none-any.whl → 0.25.6__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.
Potentially problematic release.
This version of lollms-client might be problematic. Click here for more details.
- lollms_client/__init__.py +1 -1
- lollms_client/lollms_core.py +2 -2
- {lollms_client-0.25.5.dist-info → lollms_client-0.25.6.dist-info}/METADATA +102 -1
- {lollms_client-0.25.5.dist-info → lollms_client-0.25.6.dist-info}/RECORD +7 -7
- {lollms_client-0.25.5.dist-info → lollms_client-0.25.6.dist-info}/WHEEL +0 -0
- {lollms_client-0.25.5.dist-info → lollms_client-0.25.6.dist-info}/licenses/LICENSE +0 -0
- {lollms_client-0.25.5.dist-info → lollms_client-0.25.6.dist-info}/top_level.txt +0 -0
lollms_client/__init__.py
CHANGED
|
@@ -8,7 +8,7 @@ from lollms_client.lollms_utilities import PromptReshaper # Keep general utiliti
|
|
|
8
8
|
from lollms_client.lollms_mcp_binding import LollmsMCPBinding, LollmsMCPBindingManager
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
__version__ = "0.25.
|
|
11
|
+
__version__ = "0.25.6" # Updated version
|
|
12
12
|
|
|
13
13
|
# Optionally, you could define __all__ if you want to be explicit about exports
|
|
14
14
|
__all__ = [
|
lollms_client/lollms_core.py
CHANGED
|
@@ -1595,7 +1595,7 @@ Provide your response as a single JSON object inside a JSON markdown tag. Use th
|
|
|
1595
1595
|
formatted_tools_list += "\n**request_clarification**:\nUse if the user's request is ambiguous and you can not infer a clear idea of his intent. this tool has no parameters."
|
|
1596
1596
|
formatted_tools_list += "\n**final_answer**:\nUse when you are ready to respond to the user. this tool has no parameters."
|
|
1597
1597
|
|
|
1598
|
-
if discovery_step_id: log_event("Discovering tools",MSG_TYPE.MSG_TYPE_STEP_END, event_id=discovery_step_id)
|
|
1598
|
+
if discovery_step_id: log_event("**Discovering tools**",MSG_TYPE.MSG_TYPE_STEP_END, event_id=discovery_step_id)
|
|
1599
1599
|
|
|
1600
1600
|
# --- 2. Dynamic Reasoning Loop ---
|
|
1601
1601
|
for i in range(max_reasoning_steps):
|
|
@@ -1755,7 +1755,7 @@ Provide your response as a single JSON object inside a JSON markdown tag. Use th
|
|
|
1755
1755
|
|
|
1756
1756
|
tool_calls_this_turn.append({"name": tool_name, "params": tool_params, "result": tool_result})
|
|
1757
1757
|
current_scratchpad += f"\n\n### Step {i+1}: Observation\n- **Action:** Called `{tool_name}`\n- **Result:**\n{observation_text}"
|
|
1758
|
-
log_event(f"Observation
|
|
1758
|
+
log_event(f"**Observation**: Result from `{tool_name}`:\n{dict_to_markdown(sanitized_result)}", MSG_TYPE.MSG_TYPE_OBSERVATION)
|
|
1759
1759
|
|
|
1760
1760
|
if reasoning_step_id: log_event(f"**Reasoning Step {i+1}/{max_reasoning_steps}**", MSG_TYPE.MSG_TYPE_STEP_END, event_id = reasoning_step_id)
|
|
1761
1761
|
except Exception as ex:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lollms_client
|
|
3
|
-
Version: 0.25.
|
|
3
|
+
Version: 0.25.6
|
|
4
4
|
Summary: A client library for LoLLMs generate endpoint
|
|
5
5
|
Author-email: ParisNeo <parisneoai@gmail.com>
|
|
6
6
|
License: Apache Software License
|
|
@@ -169,6 +169,107 @@ except Exception as e:
|
|
|
169
169
|
```
|
|
170
170
|
For a comprehensive guide on function calling and setting up tools, please refer to the [Usage Guide (DOC_USE.md)](DOC_USE.md).
|
|
171
171
|
|
|
172
|
+
### 🤖 Advanced Agentic Generation with RAG: `generate_with_mcp_rag`
|
|
173
|
+
|
|
174
|
+
For more complex tasks, `generate_with_mcp_rag` provides a powerful, built-in agent that uses a ReAct-style (Reason, Act) loop. This agent can reason about a user's request, use tools (MCP), retrieve information from knowledge bases (RAG), and adapt its plan based on the results of its actions.
|
|
175
|
+
|
|
176
|
+
**Key Agent Capabilities:**
|
|
177
|
+
|
|
178
|
+
* **Observe-Think-Act Loop:** The agent iteratively reviews its progress, thinks about the next logical step, and takes an action (like calling a tool).
|
|
179
|
+
* **Tool Integration (MCP):** Can use any available MCP tools, such as searching the web or executing code.
|
|
180
|
+
* **Retrieval-Augmented Generation (RAG):** You can provide one or more "data stores" (knowledge bases). The agent gains a `research::{store_name}` tool to query these stores for relevant information.
|
|
181
|
+
* **In-Memory Code Generation:** The agent has a special `generate_code` tool. This allows it to first write a piece of code (e.g., a complex Python script) and then pass that code to another tool (e.g., `python_code_interpreter`) in a subsequent step.
|
|
182
|
+
* **Stateful Progress Tracking:** Designed for rich UI experiences, it emits `step_start` and `step_end` events with unique IDs via the streaming callback. This allows an application to track the agent's individual thoughts and long-running tool calls in real-time.
|
|
183
|
+
* **Self-Correction:** Includes a `refactor_scratchpad` tool for the agent to clean up its own thought process if it becomes cluttered.
|
|
184
|
+
|
|
185
|
+
Here is an example of using the agent to answer a question by first performing RAG on a custom knowledge base and then using the retrieved information to generate and execute code.
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
import json
|
|
189
|
+
from lollms_client import LollmsClient, MSG_TYPE
|
|
190
|
+
from ascii_colors import ASCIIColors
|
|
191
|
+
|
|
192
|
+
# 1. Define a mock RAG data store and retrieval function
|
|
193
|
+
project_notes = {
|
|
194
|
+
"project_phoenix_details": "Project Phoenix has a current budget of $500,000 and an expected quarterly growth rate of 15%."
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
def retrieve_from_notes(query: str, top_k: int = 1, min_similarity: float = 0.5):
|
|
198
|
+
"""A simple keyword-based retriever for our mock data store."""
|
|
199
|
+
results = []
|
|
200
|
+
for key, text in project_notes.items():
|
|
201
|
+
if query.lower() in text.lower():
|
|
202
|
+
results.append({"source": key, "content": text})
|
|
203
|
+
return results[:top_k]
|
|
204
|
+
|
|
205
|
+
# 2. Define a detailed streaming callback to visualize the agent's process
|
|
206
|
+
def agent_streaming_callback(chunk: str, msg_type: MSG_TYPE, params: dict = None, metadata: list = None) -> bool:
|
|
207
|
+
if not params: params = {}
|
|
208
|
+
msg_id = params.get("id", "")
|
|
209
|
+
|
|
210
|
+
if msg_type == MSG_TYPE.MSG_TYPE_STEP_START:
|
|
211
|
+
ASCIIColors.yellow(f"\n>> Agent Step Start [ID: {msg_id}]: {chunk}")
|
|
212
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_STEP_END:
|
|
213
|
+
ASCIIColors.green(f"<< Agent Step End [ID: {msg_id}]: {chunk}")
|
|
214
|
+
if params.get('result'):
|
|
215
|
+
ASCIIColors.cyan(f" Result: {json.dumps(params['result'], indent=2)}")
|
|
216
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_THOUGHT_CONTENT:
|
|
217
|
+
ASCIIColors.magenta(f"\n🤔 Agent Thought: {chunk}")
|
|
218
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_TOOL_CALL:
|
|
219
|
+
ASCIIColors.blue(f"\n🛠️ Agent Action: {chunk}")
|
|
220
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_OBSERVATION:
|
|
221
|
+
ASCIIColors.cyan(f"\n👀 Agent Observation: {chunk}")
|
|
222
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_CHUNK:
|
|
223
|
+
print(chunk, end="", flush=True) # Final answer stream
|
|
224
|
+
return True
|
|
225
|
+
|
|
226
|
+
try:
|
|
227
|
+
# 3. Initialize LollmsClient with an LLM and local tools enabled
|
|
228
|
+
lc = LollmsClient(
|
|
229
|
+
binding_name="ollama", # Use Ollama
|
|
230
|
+
model_name="llama3", # Or any capable model like mistral, gemma, etc.
|
|
231
|
+
mcp_binding_name="local_mcp" # Enable local tools like python_code_interpreter
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
# 4. Define the user prompt and the RAG data store
|
|
235
|
+
prompt = "Based on my notes about Project Phoenix, write and run a Python script to calculate its projected budget after two quarters."
|
|
236
|
+
|
|
237
|
+
rag_data_store = {
|
|
238
|
+
"project_notes": {"callable": retrieve_from_notes}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
ASCIIColors.yellow(f"User Prompt: {prompt}")
|
|
242
|
+
print("\n" + "="*50 + "\nAgent is now running...\n" + "="*50)
|
|
243
|
+
|
|
244
|
+
# 5. Run the agent
|
|
245
|
+
agent_output = lc.generate_with_mcp_rag(
|
|
246
|
+
prompt=prompt,
|
|
247
|
+
use_data_store=rag_data_store,
|
|
248
|
+
use_mcps=["python_code_interpreter"], # Make specific tools available
|
|
249
|
+
streaming_callback=agent_streaming_callback,
|
|
250
|
+
max_reasoning_steps=5
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
print("\n" + "="*50 + "\nAgent finished.\n" + "="*50)
|
|
254
|
+
|
|
255
|
+
# 6. Print the final results
|
|
256
|
+
if agent_output.get("error"):
|
|
257
|
+
ASCIIColors.error(f"\nAgent Error: {agent_output['error']}")
|
|
258
|
+
else:
|
|
259
|
+
ASCIIColors.green("\n--- Final Answer ---")
|
|
260
|
+
print(agent_output.get("final_answer"))
|
|
261
|
+
|
|
262
|
+
ASCIIColors.magenta("\n--- Tool Calls ---")
|
|
263
|
+
print(json.dumps(agent_output.get("tool_calls", []), indent=2))
|
|
264
|
+
|
|
265
|
+
ASCIIColors.cyan("\n--- RAG Sources ---")
|
|
266
|
+
print(json.dumps(agent_output.get("sources", []), indent=2))
|
|
267
|
+
|
|
268
|
+
except Exception as e:
|
|
269
|
+
ASCIIColors.red(f"\nAn unexpected error occurred: {e}")
|
|
270
|
+
|
|
271
|
+
```
|
|
272
|
+
|
|
172
273
|
## Documentation
|
|
173
274
|
|
|
174
275
|
For more in-depth information, please refer to:
|
|
@@ -26,9 +26,9 @@ examples/mcp_examples/openai_mcp.py,sha256=7IEnPGPXZgYZyiES_VaUbQ6viQjenpcUxGiHE
|
|
|
26
26
|
examples/mcp_examples/run_remote_mcp_example_v2.py,sha256=bbNn93NO_lKcFzfIsdvJJijGx2ePFTYfknofqZxMuRM,14626
|
|
27
27
|
examples/mcp_examples/run_standard_mcp_example.py,sha256=GSZpaACPf3mDPsjA8esBQVUsIi7owI39ca5avsmvCxA,9419
|
|
28
28
|
examples/test_local_models/local_chat.py,sha256=slakja2zaHOEAUsn2tn_VmI4kLx6luLBrPqAeaNsix8,456
|
|
29
|
-
lollms_client/__init__.py,sha256=
|
|
29
|
+
lollms_client/__init__.py,sha256=pXsP6DSu8Afm4PZN5PmsBipV-ZOKCS81s7bngvYCcgU,1047
|
|
30
30
|
lollms_client/lollms_config.py,sha256=goEseDwDxYJf3WkYJ4IrLXwg3Tfw73CXV2Avg45M_hE,21876
|
|
31
|
-
lollms_client/lollms_core.py,sha256=
|
|
31
|
+
lollms_client/lollms_core.py,sha256=TujAapwba9gDe6EEY4olVSP-lZrLftY4LOSex-D-IPs,159610
|
|
32
32
|
lollms_client/lollms_discussion.py,sha256=By_dN3GJ7AtInkOUdcrXuVhKliBirKd3ZxFkaRmt1yM,48843
|
|
33
33
|
lollms_client/lollms_js_analyzer.py,sha256=01zUvuO2F_lnUe_0NLxe1MF5aHE1hO8RZi48mNPv-aw,8361
|
|
34
34
|
lollms_client/lollms_llm_binding.py,sha256=Kpzhs5Jx8eAlaaUacYnKV7qIq2wbME5lOEtKSfJKbpg,12161
|
|
@@ -81,8 +81,8 @@ lollms_client/tts_bindings/piper_tts/__init__.py,sha256=0IEWG4zH3_sOkSb9WbZzkeV5
|
|
|
81
81
|
lollms_client/tts_bindings/xtts/__init__.py,sha256=FgcdUH06X6ZR806WQe5ixaYx0QoxtAcOgYo87a2qxYc,18266
|
|
82
82
|
lollms_client/ttv_bindings/__init__.py,sha256=UZ8o2izQOJLQgtZ1D1cXoNST7rzqW22rL2Vufc7ddRc,3141
|
|
83
83
|
lollms_client/ttv_bindings/lollms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
84
|
-
lollms_client-0.25.
|
|
85
|
-
lollms_client-0.25.
|
|
86
|
-
lollms_client-0.25.
|
|
87
|
-
lollms_client-0.25.
|
|
88
|
-
lollms_client-0.25.
|
|
84
|
+
lollms_client-0.25.6.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
85
|
+
lollms_client-0.25.6.dist-info/METADATA,sha256=dqV9ITu1ABd8rtnvPb4N7K3qUTCD6stQJhys08xoUJs,18659
|
|
86
|
+
lollms_client-0.25.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
87
|
+
lollms_client-0.25.6.dist-info/top_level.txt,sha256=NI_W8S4OYZvJjb0QWMZMSIpOrYzpqwPGYaklhyWKH2w,23
|
|
88
|
+
lollms_client-0.25.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|