clap-agents 0.1.1__tar.gz → 0.2.2__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.
Files changed (79) hide show
  1. clap_agents-0.2.2/.gitignore +23 -0
  2. clap_agents-0.2.2/GITCLAP.png +0 -0
  3. clap_agents-0.2.2/PIP CLAP.png +0 -0
  4. {clap_agents-0.1.1 → clap_agents-0.2.2}/PKG-INFO +201 -23
  5. clap_agents-0.2.2/README.md +253 -0
  6. clap_agents-0.2.2/changelog.md +27 -0
  7. clap_agents-0.2.2/examples/CLAP-TEST-SUITE.py +304 -0
  8. clap_agents-0.2.2/examples/all_func.py +180 -0
  9. clap_agents-0.2.2/examples/document_ingestion.py +158 -0
  10. clap_agents-0.2.2/examples/email_test.py +48 -0
  11. {clap_agents-0.1.1 → clap_agents-0.2.2}/examples/google_mcp.py +5 -16
  12. clap_agents-0.2.2/examples/huge_rag.py +101 -0
  13. clap_agents-0.2.2/examples/local_rag.py +71 -0
  14. {clap_agents-0.1.1 → clap_agents-0.2.2}/examples/mcp_test_agent.py +2 -5
  15. clap_agents-0.2.2/examples/mcp_test_suite.py +87 -0
  16. clap_agents-0.2.2/examples/ollama_test.py +71 -0
  17. clap_agents-0.2.2/examples/qdrant_ingestion.py +188 -0
  18. clap_agents-0.2.2/examples/rag_all_functionalities.py +182 -0
  19. clap_agents-0.2.2/examples/rag_test.py +126 -0
  20. {clap_agents-0.1.1 → clap_agents-0.2.2}/examples/react_test.py +1 -1
  21. clap_agents-0.2.2/examples/requirements.txt +28 -0
  22. {clap_agents-0.1.1 → clap_agents-0.2.2}/examples/scraping_test.py +5 -4
  23. {clap_agents-0.1.1 → clap_agents-0.2.2}/examples/simple_react_agent.py +4 -6
  24. {clap_agents-0.1.1 → clap_agents-0.2.2}/examples/team_test.py +0 -1
  25. {clap_agents-0.1.1 → clap_agents-0.2.2}/examples/test_agent.py +3 -2
  26. clap_agents-0.2.2/examples/tool_agent_rag.py +88 -0
  27. {clap_agents-0.1.1 → clap_agents-0.2.2}/pyproject.toml +33 -12
  28. clap_agents-0.2.2/src/clap/__init__.py +28 -0
  29. clap_agents-0.2.2/src/clap/embedding/__init__.py +21 -0
  30. clap_agents-0.2.2/src/clap/embedding/base_embedding.py +28 -0
  31. clap_agents-0.2.2/src/clap/embedding/fastembed_embedding.py +75 -0
  32. clap_agents-0.2.2/src/clap/embedding/ollama_embedding.py +76 -0
  33. clap_agents-0.2.2/src/clap/embedding/sentence_transformer_embedding.py +44 -0
  34. clap_agents-0.2.2/src/clap/llm_services/__init__.py +15 -0
  35. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/llm_services/base.py +3 -6
  36. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/llm_services/google_openai_compat_service.py +1 -5
  37. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/llm_services/groq_service.py +5 -13
  38. clap_agents-0.2.2/src/clap/llm_services/ollama_service.py +101 -0
  39. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/mcp_client/client.py +13 -25
  40. clap_agents-0.2.2/src/clap/multiagent_pattern/agent.py +201 -0
  41. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/multiagent_pattern/team.py +54 -29
  42. clap_agents-0.2.2/src/clap/react_pattern/react_agent.py +478 -0
  43. clap_agents-0.2.2/src/clap/tool_pattern/tool.py +158 -0
  44. clap_agents-0.2.2/src/clap/tool_pattern/tool_agent.py +241 -0
  45. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/tools/__init__.py +1 -1
  46. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/tools/email_tools.py +16 -19
  47. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/tools/web_crawler.py +26 -18
  48. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/utils/completions.py +35 -37
  49. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/utils/extraction.py +3 -3
  50. clap_agents-0.2.2/src/clap/utils/rag_utils.py +183 -0
  51. clap_agents-0.2.2/src/clap/vector_stores/__init__.py +16 -0
  52. clap_agents-0.2.2/src/clap/vector_stores/base.py +85 -0
  53. clap_agents-0.2.2/src/clap/vector_stores/chroma_store.py +142 -0
  54. clap_agents-0.2.2/src/clap/vector_stores/qdrant_store.py +155 -0
  55. clap_agents-0.1.1/.gitignore +0 -7
  56. clap_agents-0.1.1/README.md +0 -104
  57. clap_agents-0.1.1/calc_test.py +0 -56
  58. clap_agents-0.1.1/example_server.py +0 -48
  59. clap_agents-0.1.1/examples/email_test.py +0 -29
  60. clap_agents-0.1.1/examples/requirements.txt +0 -40
  61. clap_agents-0.1.1/src/clap/__init__.py +0 -57
  62. clap_agents-0.1.1/src/clap/multiagent_pattern/agent.py +0 -128
  63. clap_agents-0.1.1/src/clap/react_pattern/react_agent.py +0 -265
  64. clap_agents-0.1.1/src/clap/tool_pattern/tool.py +0 -229
  65. clap_agents-0.1.1/src/clap/tool_pattern/tool_agent.py +0 -241
  66. clap_agents-0.1.1/src/clap/utils/__init__.py +0 -0
  67. {clap_agents-0.1.1 → clap_agents-0.2.2}/LICENSE +0 -0
  68. {clap_agents-0.1.1 → clap_agents-0.2.2}/examples/google_agent.py +0 -0
  69. {clap_agents-0.1.1 → clap_agents-0.2.2}/examples/google_team.py +0 -0
  70. {clap_agents-0.1.1 → clap_agents-0.2.2}/examples/mcp_team_agent.py +0 -0
  71. {clap_agents-0.1.1 → clap_agents-0.2.2}/simple2_mcp.py +0 -0
  72. {clap_agents-0.1.1 → clap_agents-0.2.2}/simple_mcp.py +0 -0
  73. {clap_agents-0.1.1/src/clap/llm_services → clap_agents-0.2.2/src/clap/mcp_client}/__init__.py +0 -0
  74. {clap_agents-0.1.1/src/clap/mcp_client → clap_agents-0.2.2/src/clap/multiagent_pattern}/__init__.py +0 -0
  75. {clap_agents-0.1.1/src/clap/multiagent_pattern → clap_agents-0.2.2/src/clap/react_pattern}/__init__.py +0 -0
  76. {clap_agents-0.1.1/src/clap/react_pattern → clap_agents-0.2.2/src/clap/tool_pattern}/__init__.py +0 -0
  77. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/tools/web_search.py +0 -0
  78. {clap_agents-0.1.1/src/clap/tool_pattern → clap_agents-0.2.2/src/clap/utils}/__init__.py +0 -0
  79. {clap_agents-0.1.1 → clap_agents-0.2.2}/src/clap/utils/logging.py +0 -0
@@ -0,0 +1,23 @@
1
+ # macOS
2
+ .DS_Store
3
+
4
+ # Python
5
+ .env
6
+ __pycache__/
7
+ *.py[cod]
8
+
9
+ # IDE/Editor specific (Optional but good)
10
+ .vscode/
11
+ .idea/
12
+
13
+ # Virtual Environments (IMPORTANT!)
14
+ .venv/
15
+ venv/
16
+ env/
17
+ *.venv/
18
+ clap-test/ # Or whatever you named your conda test env if created inside the project
19
+
20
+ # Build artifacts (Recommended)
21
+ dist/
22
+ build/
23
+ *.egg-info/
Binary file
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clap-agents
3
- Version: 0.1.1
3
+ Version: 0.2.2
4
4
  Summary: A Python framework for building cognitive agentic patterns including ReAct agents, Multi-Agent Teams, native tool calling, and MCP client integration.
5
5
  Project-URL: Homepage, https://github.com/MaitreyaM/CLAP-AGENTS.git
6
6
  Project-URL: Repository, https://github.com/MaitreyaM/CLAP-AGENTS.git
@@ -233,44 +233,93 @@ Requires-Dist: openai>=1.0.0
233
233
  Requires-Dist: pydantic<3.0.0,>=2.7.2
234
234
  Requires-Dist: requests
235
235
  Provides-Extra: all
236
- Requires-Dist: clap[standard-tools,viz]; extra == 'all'
236
+ Requires-Dist: chromadb>=0.5.0; extra == 'all'
237
+ Requires-Dist: crawl4ai; extra == 'all'
238
+ Requires-Dist: fastembed>=0.2.0; extra == 'all'
239
+ Requires-Dist: graphviz; extra == 'all'
240
+ Requires-Dist: ollama>=0.2.0; extra == 'all'
241
+ Requires-Dist: pandas; extra == 'all'
242
+ Requires-Dist: pypdf; extra == 'all'
243
+ Requires-Dist: qdrant-client[fastembed]>=1.7.0; extra == 'all'
244
+ Requires-Dist: sentence-transformers; extra == 'all'
245
+ Provides-Extra: chromadb
246
+ Requires-Dist: chromadb>=0.5.0; extra == 'chromadb'
247
+ Provides-Extra: fastembed
248
+ Requires-Dist: fastembed>=0.2.0; extra == 'fastembed'
249
+ Provides-Extra: ollama
250
+ Requires-Dist: ollama>=0.2.0; extra == 'ollama'
251
+ Provides-Extra: pandas
252
+ Requires-Dist: pandas; extra == 'pandas'
253
+ Provides-Extra: pdf
254
+ Requires-Dist: pypdf; extra == 'pdf'
255
+ Provides-Extra: qdrant
256
+ Requires-Dist: qdrant-client[fastembed]>=1.7.0; extra == 'qdrant'
257
+ Provides-Extra: rag
258
+ Requires-Dist: chromadb>=0.5.0; extra == 'rag'
259
+ Requires-Dist: fastembed>=0.2.0; extra == 'rag'
260
+ Requires-Dist: ollama>=0.2.0; extra == 'rag'
261
+ Requires-Dist: pypdf; extra == 'rag'
262
+ Requires-Dist: qdrant-client[fastembed]>=1.7.0; extra == 'rag'
263
+ Requires-Dist: sentence-transformers; extra == 'rag'
264
+ Provides-Extra: sentence-transformers
265
+ Requires-Dist: sentence-transformers; extra == 'sentence-transformers'
237
266
  Provides-Extra: standard-tools
238
267
  Requires-Dist: crawl4ai; extra == 'standard-tools'
239
268
  Provides-Extra: viz
240
269
  Requires-Dist: graphviz; extra == 'viz'
241
270
  Description-Content-Type: text/markdown
242
271
 
243
- # CLAP - Cognitive Layer Agents Package
272
+ <p align="center">
273
+ <img src="GITCLAP.png" alt="CLAP Logo" width="700" height="200"/>
274
+ </p>
244
275
 
245
- [![PyPI version](https://img.shields.io/pypi/v/CLAP.svg)](https://pypi.org/project/CLAP/)
276
+ # CLAP - Cognitive Layer Agent Package
277
+
278
+ [![PyPI version](https://img.shields.io/pypi/v/clap-agents.svg)](https://pypi.org/project/clap-agents/)
246
279
  [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
247
- [![Python Version](https://img.shields.io/pypi/pyversions/CLAP.svg)](https://pypi.org/project/CLAP/)
248
- <!-- Add other badges as desired, e.g., build status, coverage -->
280
+ [![Python Version](https://img.shields.io/pypi/pyversions/clap-agents.svg)](https://pypi.org/project/clap-agents/)
249
281
 
250
- **CLAP (Cognitive Layer Agent Package)** is a Python framework providing building blocks for creating sophisticated AI agents based on modern agentic patterns. It enables developers to easily construct agents capable of reasoning, planning, and interacting with external tools and systems.
282
+ **CLAP (Cognitive Layer Agent Package)** is a Python framework providing building blocks for creating sophisticated AI agents based on modern agentic patterns. It enables developers to easily construct agents capable of reasoning, planning, and interacting with external tools, systems, and knowledge bases.
251
283
 
252
284
  Built with an asynchronous core (`asyncio`), CLAP offers flexibility and performance for complex agentic workflows.
253
285
 
286
+ <p align="center">
287
+ <img src="PIP CLAP.png" alt="CLAP Pip Install" width="700" height="200"/> <!-- Updated alt text -->
288
+ </p>
289
+
254
290
  ## Key Features
255
291
 
256
292
  * **Modular Agent Patterns:**
257
- * **ReAct Agent:** Implements the Reason-Act loop with robust thought-prompting and native tool calling.
293
+ * **ReAct Agent:** Implements the Reason-Act loop with robust thought-prompting and native tool calling. Ideal for complex reasoning and RAG.
294
+ * **Tool Agent:** A straightforward agent for single-step tool usage, including simple RAG.
258
295
  * **Multi-Agent Teams:** Define teams of specialized agents with dependencies, enabling collaborative task execution (sequential or parallel).
259
- * **Simple Tool Agent:** A straightforward agent for single-step tool usage.
260
296
  * **Advanced Tool Integration:**
261
297
  * **Native LLM Tool Calling:** Leverages modern LLM APIs for reliable tool execution.
262
298
  * **Local Tools:** Easily define and use local Python functions (both synchronous and asynchronous) as tools using the `@tool` decorator.
263
299
  * **Remote Tools (MCP):** Integrates with [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers via the included `MCPClientManager`, allowing agents to discover and use tools exposed by external systems (currently supports SSE transport).
264
- * **Robust Validation:** Uses `jsonschema` for strict validation of tool arguments provided by the LLM.
300
+ * **Robust Validation & Coercion:** Uses `jsonschema` for strict validation of tool arguments and attempts type coercion for common LLM outputs (e.g., string numbers to integers).
301
+ * **Retrieval Augmented Generation (RAG) Capabilities:**
302
+ * **`VectorStoreInterface`:** An abstraction for interacting with various vector databases.
303
+ * **Supported Vector Stores:**
304
+ * **ChromaDB:** (`ChromaStore`) For local or self-hosted vector storage.
305
+ * **Qdrant:** (`QdrantStore`) For local (in-memory or file-based) vector storage.
306
+ * **`EmbeddingFunctionInterface`:** A protocol for consistent interaction with different embedding models.
307
+ * **Supported Embedding Function Wrappers:**
308
+ * `SentenceTransformerEmbeddings`: Uses models from the `sentence-transformers` library.
309
+ * `OllamaEmbeddings`: Generates embeddings using models running locally via Ollama.
310
+ * `FastEmbedEmbeddings`: Utilizes the `fastembed` library for CPU-optimized embeddings. (Note: Performance for very large batch ingestions via the async wrapper might vary based on CPU and may be slower than SentenceTransformers for initial bulk loads.)
311
+ * **RAG-Aware Agents:** Both `Agent` (via `ReactAgent`) and `ToolAgent` can be equipped with a `vector_store` to perform `vector_query` tool calls, enabling them to retrieve context before responding.
312
+ * **Utilities:** Includes basic PDF and CSV text loaders and chunking strategies in `clap.utils.rag_utils`.
265
313
  * **Pluggable LLM Backends:**
266
314
  * Uses a **Strategy Pattern** (`LLMServiceInterface`) to abstract LLM interactions.
267
315
  * Includes ready-to-use service implementations for:
268
316
  * **Groq:** (`GroqService`)
269
317
  * **Google Generative AI (Gemini):** (`GoogleOpenAICompatService` via OpenAI compatibility layer)
318
+ * **Ollama (Local LLMs):** (`OllamaOpenAICompatService` also known as `OllamaService` via OpenAI compatibility layer, allowing use of locally run models like Llama 3, Mistral, etc.)
270
319
  * Easily extensible to support other LLM providers.
271
320
  * **Asynchronous Core:** Built entirely on `asyncio` for efficient I/O operations and potential concurrency.
272
- * **Structured Context Passing:** Enables clear and organized information flow between agents in a team using Python dictionaries.
273
- * **Built-in Tools:** Includes helpers for web search, web scraping, and email interaction (optional dependencies may apply).
321
+ * **Structured Context Passing:** Enables clear and organized information flow between agents in a team.
322
+ * **Built-in Tools:** Includes helpers for web search (`duckduckgo_search`). More available via optional dependencies.
274
323
 
275
324
  ## Installation
276
325
 
@@ -278,13 +327,40 @@ Ensure you have Python 3.10 or later installed.
278
327
 
279
328
  ```bash
280
329
  pip install clap-agents
330
+ ```
331
+
332
+ Ensure you have Python 3.10 or later installed.
333
+
334
+ ```bash
335
+ pip install clap-agents
336
+
281
337
 
338
+ To use specific features, you might need to install optional dependencies:
339
+ # For Qdrant support (includes fastembed)
340
+ pip install "clap-agents[qdrant]"
341
+
342
+ # For ChromaDB support
343
+ pip install "clap-agents[chromadb]"
344
+
345
+ # For Ollama (LLM and/or Embeddings)
346
+ pip install "clap-agents[ollama]"
347
+
348
+ # For other tools like web crawling or visualization
349
+ pip install "clap-agents[standard_tools,viz]"
350
+
351
+ # To install all major optional dependencies
352
+ pip install "clap-agents[all]"
353
+ ```
354
+
355
+
356
+ Check the pyproject.toml for the full list of [project.optional-dependencies]. You will also need to have external services like Ollama or Qdrant (if used locally) running.
282
357
  Depending on the tools or LLM backends you intend to use, you might need additional dependencies listed in the pyproject.toml (e.g., groq, openai, mcp, jsonschema, requests, duckduckgo-search, graphviz). Check the [project.dependencies] and [project.optional-dependencies] sections.
283
358
 
284
359
 
285
- Quick Start: Simple Tool calling Agent with a Local Tool
360
+ ## Quick Start: Simple Tool calling Agent with a Local Tool
286
361
  This example demonstrates creating a Tool calling agent using the Groq backend and a local tool
287
362
 
363
+ ```
288
364
  from dotenv import load_dotenv
289
365
  from clap import ToolAgent
290
366
  from clap import duckduckgo_search
@@ -292,25 +368,24 @@ from clap import duckduckgo_search
292
368
  load_dotenv()
293
369
 
294
370
  async def main():
295
- agent = ToolAgent(tools=duckduckgo_search, model="llama-3.3-70b-versatile")
371
+ agent = ToolAgent(tools=duckduckgo_search, model="meta-llama/llama-4-scout-17b-16e-instruct")
296
372
  user_query = "Search the web for recent news about AI advancements."
297
373
  response = await agent.run(user_msg=user_query)
298
374
  print(f"Response:\n{response}")
299
375
 
300
376
  asyncio.run(main())
377
+ ```
301
378
 
302
379
 
303
-
304
- Quick Start: Simple ReAct Agent with a Local Tool
380
+ ## Quick Start: Simple ReAct Agent with a Local Tool
305
381
  This example demonstrates creating a ReAct agent using the Groq backend and a local tool.
306
382
 
307
-
383
+ ```
308
384
  import asyncio
309
385
  import os
310
386
  from dotenv import load_dotenv
311
387
  from clap import ReactAgent, tool, GroqService
312
388
 
313
- # --- Setup ---
314
389
  load_dotenv()
315
390
  @tool
316
391
  def get_word_length(word: str) -> int:
@@ -333,14 +408,117 @@ async def main():
333
408
  print(response)
334
409
 
335
410
  asyncio.run(main())
411
+ ```
412
+
413
+ ## Quick Start: Simple Tool-Calling Agent with Ollama
414
+ This example demonstrates a ToolAgent using a local Ollama model and a local tool.
415
+ Ensure Ollama is running and you have pulled the model (e.g., ollama pull llama3).
416
+
417
+ ```
418
+ import asyncio
419
+ from dotenv import load_dotenv
420
+ from clap import ToolAgent, tool, OllamaService # Assuming OllamaService is your OllamaOpenAICompatService
421
+
422
+ load_dotenv()
423
+
424
+ @tool
425
+ def get_capital(country: str) -> str:
426
+ """Returns the capital of a country."""
427
+ if country.lower() == "france": return "Paris"
428
+ return f"I don't know the capital of {country}."
429
+
430
+ async def main():
431
+ # Initialize the Ollama service
432
+ ollama_llm_service = OllamaService(default_model="llama3") # Specify your Ollama model
433
+
434
+ agent = ToolAgent(
435
+ llm_service=ollama_llm_service,
436
+ model="llama3", # Model name for this agent
437
+ tools=[get_capital]
438
+ )
439
+ user_query = "What is the capital of France?"
440
+ response = await agent.run(user_msg=user_query)
441
+ print(f"Query: {user_query}\nResponse:\n{response}")
336
442
 
443
+ await ollama_llm_service.close() # Important for OllamaService
337
444
 
338
- Exploring Further
339
- Multi-Agent Teams: See examples/team_agent.py for setting up sequential or parallel agent workflows.
340
- MCP Integration: Check examples/minimal_react_mcp_test.py and examples/test_tool_agent_mcp.py (ensure the corresponding MCP server like examples/minimal_mcp_server.py is running).
341
- Google GenAI: Modify the Quick Start to use GoogleOpenAICompatService instead of GroqService (ensure GOOGLE_API_KEY is set and openai library is installed).
342
- Built-in Tools: Explore the tools provided in clap.tools (like duckduckgo_search, scrape_url, etc.).
445
+ if __name__ == "__main__":
446
+ asyncio.run(main())
343
447
 
448
+ ```
449
+
450
+ ## Quick Start: RAG Agent with Qdrant and Ollama Embeddings
451
+ This example shows an Agent performing RAG using Ollama for embeddings and Qdrant as the vector store.
452
+ Ensure Ollama is running (with nomic-embed-text and llama3 pulled) and Qdrant is running (e.g., via Docker).
453
+ ```
454
+ import asyncio
455
+ import os
456
+ import shutil
457
+ from dotenv import load_dotenv
458
+ from clap import Agent, QdrantStore, OllamaEmbeddings, OllamaService
459
+ from clap.utils.rag_utils import chunk_text_by_fixed_size
460
+ from qdrant_client import models as qdrant_models # If needed for distance
461
+
462
+ load_dotenv()
463
+
464
+ OLLAMA_HOST = "http://localhost:11434"
465
+ EMBED_MODEL = "nomic-embed-text"
466
+ LLM_MODEL = "llama3"
467
+ DB_PATH = "./temp_rag_db_ollama_qdrant"
468
+ COLLECTION = "my_rag_docs"
469
+
470
+ async def main():
471
+ if os.path.exists(DB_PATH): shutil.rmtree(DB_PATH)
472
+
473
+ ollama_ef = OllamaEmbeddings(model_name=EMBED_MODEL, ollama_host=OLLAMA_HOST)
474
+ vector_store = await QdrantStore.create(
475
+ collection_name=COLLECTION,
476
+ embedding_function=ollama_ef,
477
+ path=DB_PATH, # For local file-based Qdrant
478
+ recreate_collection_if_exists=True
479
+ )
480
+
481
+ sample_texts = ["The sky is blue due to Rayleigh scattering.", "Large language models are powerful."]
482
+ chunks = [chunk for text in sample_texts for chunk in chunk_text_by_fixed_size(text, 100, 10)]
483
+ ids = [str(i) for i in range(len(chunks))] # Qdrant needs UUIDs; QdrantStore handles this
484
+
485
+ if chunks:
486
+ await vector_store.add_documents(documents=chunks, ids=ids)
487
+ print(f"Ingested {len(chunks)} chunks.")
488
+
489
+ ollama_llm_service = OllamaService(default_model=LLM_MODEL, base_url=f"{OLLAMA_HOST}/v1")
490
+ rag_agent = Agent(
491
+ name="RAGMaster",
492
+ backstory="I answer questions using provided documents.",
493
+ task_description="Why is the sky blue according to the documents?", # This becomes the User Query
494
+ llm_service=ollama_llm_service,
495
+ model=LLM_MODEL,
496
+ vector_store=vector_store
497
+ )
498
+
499
+ response = await rag_agent.run()
500
+ print(f"Query: {rag_agent.task_description}\nResponse:\n{response.get('output')}")
501
+
502
+ await vector_store.close()
503
+ await ollama_llm_service.close()
504
+ if os.path.exists(DB_PATH): shutil.rmtree(DB_PATH)
505
+
506
+ asyncio.run(main())
507
+ ```
508
+
509
+ ## Exploring Further
510
+
511
+
512
+ # Multi-Agent Teams: See examples/test_clap_comprehensive_suite.py and other team examples for setting up sequential or parallel agent workflows.
513
+
514
+ # MCP Integration: Check examples/test_clap_comprehensive_suite.py (ensure corresponding MCP servers from examples/simple_mcp.py etc. are running).
515
+
516
+ # Other LLM Services (Groq, Google Gemini , Ollama): Modify the Quick Starts to use GroqService or GoogleOpenAICompatService (ensure API keys are set).
517
+
518
+ # Different Vector Stores & Embedding Functions: Experiment with ChromaStore, QdrantStore, SentenceTransformerEmbeddings, FastEmbedEmbeddings, and OllamaEmbeddings as shown in the comprehensive test suite.
344
519
 
345
520
  License
346
521
  This project is licensed under the terms of the Apache License 2.0. See the LICENSE file for details.
522
+
523
+
524
+
@@ -0,0 +1,253 @@
1
+ <p align="center">
2
+ <img src="GITCLAP.png" alt="CLAP Logo" width="700" height="200"/>
3
+ </p>
4
+
5
+ # CLAP - Cognitive Layer Agent Package
6
+
7
+ [![PyPI version](https://img.shields.io/pypi/v/clap-agents.svg)](https://pypi.org/project/clap-agents/)
8
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
9
+ [![Python Version](https://img.shields.io/pypi/pyversions/clap-agents.svg)](https://pypi.org/project/clap-agents/)
10
+
11
+ **CLAP (Cognitive Layer Agent Package)** is a Python framework providing building blocks for creating sophisticated AI agents based on modern agentic patterns. It enables developers to easily construct agents capable of reasoning, planning, and interacting with external tools, systems, and knowledge bases.
12
+
13
+ Built with an asynchronous core (`asyncio`), CLAP offers flexibility and performance for complex agentic workflows.
14
+
15
+ <p align="center">
16
+ <img src="PIP CLAP.png" alt="CLAP Pip Install" width="700" height="200"/> <!-- Updated alt text -->
17
+ </p>
18
+
19
+ ## Key Features
20
+
21
+ * **Modular Agent Patterns:**
22
+ * **ReAct Agent:** Implements the Reason-Act loop with robust thought-prompting and native tool calling. Ideal for complex reasoning and RAG.
23
+ * **Tool Agent:** A straightforward agent for single-step tool usage, including simple RAG.
24
+ * **Multi-Agent Teams:** Define teams of specialized agents with dependencies, enabling collaborative task execution (sequential or parallel).
25
+ * **Advanced Tool Integration:**
26
+ * **Native LLM Tool Calling:** Leverages modern LLM APIs for reliable tool execution.
27
+ * **Local Tools:** Easily define and use local Python functions (both synchronous and asynchronous) as tools using the `@tool` decorator.
28
+ * **Remote Tools (MCP):** Integrates with [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers via the included `MCPClientManager`, allowing agents to discover and use tools exposed by external systems (currently supports SSE transport).
29
+ * **Robust Validation & Coercion:** Uses `jsonschema` for strict validation of tool arguments and attempts type coercion for common LLM outputs (e.g., string numbers to integers).
30
+ * **Retrieval Augmented Generation (RAG) Capabilities:**
31
+ * **`VectorStoreInterface`:** An abstraction for interacting with various vector databases.
32
+ * **Supported Vector Stores:**
33
+ * **ChromaDB:** (`ChromaStore`) For local or self-hosted vector storage.
34
+ * **Qdrant:** (`QdrantStore`) For local (in-memory or file-based) vector storage.
35
+ * **`EmbeddingFunctionInterface`:** A protocol for consistent interaction with different embedding models.
36
+ * **Supported Embedding Function Wrappers:**
37
+ * `SentenceTransformerEmbeddings`: Uses models from the `sentence-transformers` library.
38
+ * `OllamaEmbeddings`: Generates embeddings using models running locally via Ollama.
39
+ * `FastEmbedEmbeddings`: Utilizes the `fastembed` library for CPU-optimized embeddings. (Note: Performance for very large batch ingestions via the async wrapper might vary based on CPU and may be slower than SentenceTransformers for initial bulk loads.)
40
+ * **RAG-Aware Agents:** Both `Agent` (via `ReactAgent`) and `ToolAgent` can be equipped with a `vector_store` to perform `vector_query` tool calls, enabling them to retrieve context before responding.
41
+ * **Utilities:** Includes basic PDF and CSV text loaders and chunking strategies in `clap.utils.rag_utils`.
42
+ * **Pluggable LLM Backends:**
43
+ * Uses a **Strategy Pattern** (`LLMServiceInterface`) to abstract LLM interactions.
44
+ * Includes ready-to-use service implementations for:
45
+ * **Groq:** (`GroqService`)
46
+ * **Google Generative AI (Gemini):** (`GoogleOpenAICompatService` via OpenAI compatibility layer)
47
+ * **Ollama (Local LLMs):** (`OllamaOpenAICompatService` also known as `OllamaService` via OpenAI compatibility layer, allowing use of locally run models like Llama 3, Mistral, etc.)
48
+ * Easily extensible to support other LLM providers.
49
+ * **Asynchronous Core:** Built entirely on `asyncio` for efficient I/O operations and potential concurrency.
50
+ * **Structured Context Passing:** Enables clear and organized information flow between agents in a team.
51
+ * **Built-in Tools:** Includes helpers for web search (`duckduckgo_search`). More available via optional dependencies.
52
+
53
+ ## Installation
54
+
55
+ Ensure you have Python 3.10 or later installed.
56
+
57
+ ```bash
58
+ pip install clap-agents
59
+ ```
60
+
61
+ Ensure you have Python 3.10 or later installed.
62
+
63
+ ```bash
64
+ pip install clap-agents
65
+
66
+
67
+ To use specific features, you might need to install optional dependencies:
68
+ # For Qdrant support (includes fastembed)
69
+ pip install "clap-agents[qdrant]"
70
+
71
+ # For ChromaDB support
72
+ pip install "clap-agents[chromadb]"
73
+
74
+ # For Ollama (LLM and/or Embeddings)
75
+ pip install "clap-agents[ollama]"
76
+
77
+ # For other tools like web crawling or visualization
78
+ pip install "clap-agents[standard_tools,viz]"
79
+
80
+ # To install all major optional dependencies
81
+ pip install "clap-agents[all]"
82
+ ```
83
+
84
+
85
+ Check the pyproject.toml for the full list of [project.optional-dependencies]. You will also need to have external services like Ollama or Qdrant (if used locally) running.
86
+ Depending on the tools or LLM backends you intend to use, you might need additional dependencies listed in the pyproject.toml (e.g., groq, openai, mcp, jsonschema, requests, duckduckgo-search, graphviz). Check the [project.dependencies] and [project.optional-dependencies] sections.
87
+
88
+
89
+ ## Quick Start: Simple Tool calling Agent with a Local Tool
90
+ This example demonstrates creating a Tool calling agent using the Groq backend and a local tool
91
+
92
+ ```
93
+ from dotenv import load_dotenv
94
+ from clap import ToolAgent
95
+ from clap import duckduckgo_search
96
+
97
+ load_dotenv()
98
+
99
+ async def main():
100
+ agent = ToolAgent(tools=duckduckgo_search, model="meta-llama/llama-4-scout-17b-16e-instruct")
101
+ user_query = "Search the web for recent news about AI advancements."
102
+ response = await agent.run(user_msg=user_query)
103
+ print(f"Response:\n{response}")
104
+
105
+ asyncio.run(main())
106
+ ```
107
+
108
+
109
+ ## Quick Start: Simple ReAct Agent with a Local Tool
110
+ This example demonstrates creating a ReAct agent using the Groq backend and a local tool.
111
+
112
+ ```
113
+ import asyncio
114
+ import os
115
+ from dotenv import load_dotenv
116
+ from clap import ReactAgent, tool, GroqService
117
+
118
+ load_dotenv()
119
+ @tool
120
+ def get_word_length(word: str) -> int:
121
+ """Calculates the length of a word."""
122
+ print(f"[Local Tool] Calculating length of: {word}")
123
+ return len(word)
124
+
125
+ async def main():
126
+ groq_service = GroqService() # Your service of choice (either groq or Google)
127
+ agent = ReactAgent(
128
+ llm_service=groq_service,
129
+ model="llama-3.3-70b-versatile", # Or another Groq model
130
+ tools=[get_word_length], # Provide the local tool
131
+ # system_prompt="You are a helpful assistant." # Optional base prompt
132
+ )
133
+
134
+ user_query = "How many letters are in the word 'framework'?"
135
+ response = await agent.run(user_msg=user_query)
136
+
137
+ print(response)
138
+
139
+ asyncio.run(main())
140
+ ```
141
+
142
+ ## Quick Start: Simple Tool-Calling Agent with Ollama
143
+ This example demonstrates a ToolAgent using a local Ollama model and a local tool.
144
+ Ensure Ollama is running and you have pulled the model (e.g., ollama pull llama3).
145
+
146
+ ```
147
+ import asyncio
148
+ from dotenv import load_dotenv
149
+ from clap import ToolAgent, tool, OllamaService # Assuming OllamaService is your OllamaOpenAICompatService
150
+
151
+ load_dotenv()
152
+
153
+ @tool
154
+ def get_capital(country: str) -> str:
155
+ """Returns the capital of a country."""
156
+ if country.lower() == "france": return "Paris"
157
+ return f"I don't know the capital of {country}."
158
+
159
+ async def main():
160
+ # Initialize the Ollama service
161
+ ollama_llm_service = OllamaService(default_model="llama3") # Specify your Ollama model
162
+
163
+ agent = ToolAgent(
164
+ llm_service=ollama_llm_service,
165
+ model="llama3", # Model name for this agent
166
+ tools=[get_capital]
167
+ )
168
+ user_query = "What is the capital of France?"
169
+ response = await agent.run(user_msg=user_query)
170
+ print(f"Query: {user_query}\nResponse:\n{response}")
171
+
172
+ await ollama_llm_service.close() # Important for OllamaService
173
+
174
+ if __name__ == "__main__":
175
+ asyncio.run(main())
176
+
177
+ ```
178
+
179
+ ## Quick Start: RAG Agent with Qdrant and Ollama Embeddings
180
+ This example shows an Agent performing RAG using Ollama for embeddings and Qdrant as the vector store.
181
+ Ensure Ollama is running (with nomic-embed-text and llama3 pulled) and Qdrant is running (e.g., via Docker).
182
+ ```
183
+ import asyncio
184
+ import os
185
+ import shutil
186
+ from dotenv import load_dotenv
187
+ from clap import Agent, QdrantStore, OllamaEmbeddings, OllamaService
188
+ from clap.utils.rag_utils import chunk_text_by_fixed_size
189
+ from qdrant_client import models as qdrant_models # If needed for distance
190
+
191
+ load_dotenv()
192
+
193
+ OLLAMA_HOST = "http://localhost:11434"
194
+ EMBED_MODEL = "nomic-embed-text"
195
+ LLM_MODEL = "llama3"
196
+ DB_PATH = "./temp_rag_db_ollama_qdrant"
197
+ COLLECTION = "my_rag_docs"
198
+
199
+ async def main():
200
+ if os.path.exists(DB_PATH): shutil.rmtree(DB_PATH)
201
+
202
+ ollama_ef = OllamaEmbeddings(model_name=EMBED_MODEL, ollama_host=OLLAMA_HOST)
203
+ vector_store = await QdrantStore.create(
204
+ collection_name=COLLECTION,
205
+ embedding_function=ollama_ef,
206
+ path=DB_PATH, # For local file-based Qdrant
207
+ recreate_collection_if_exists=True
208
+ )
209
+
210
+ sample_texts = ["The sky is blue due to Rayleigh scattering.", "Large language models are powerful."]
211
+ chunks = [chunk for text in sample_texts for chunk in chunk_text_by_fixed_size(text, 100, 10)]
212
+ ids = [str(i) for i in range(len(chunks))] # Qdrant needs UUIDs; QdrantStore handles this
213
+
214
+ if chunks:
215
+ await vector_store.add_documents(documents=chunks, ids=ids)
216
+ print(f"Ingested {len(chunks)} chunks.")
217
+
218
+ ollama_llm_service = OllamaService(default_model=LLM_MODEL, base_url=f"{OLLAMA_HOST}/v1")
219
+ rag_agent = Agent(
220
+ name="RAGMaster",
221
+ backstory="I answer questions using provided documents.",
222
+ task_description="Why is the sky blue according to the documents?", # This becomes the User Query
223
+ llm_service=ollama_llm_service,
224
+ model=LLM_MODEL,
225
+ vector_store=vector_store
226
+ )
227
+
228
+ response = await rag_agent.run()
229
+ print(f"Query: {rag_agent.task_description}\nResponse:\n{response.get('output')}")
230
+
231
+ await vector_store.close()
232
+ await ollama_llm_service.close()
233
+ if os.path.exists(DB_PATH): shutil.rmtree(DB_PATH)
234
+
235
+ asyncio.run(main())
236
+ ```
237
+
238
+ ## Exploring Further
239
+
240
+
241
+ # Multi-Agent Teams: See examples/test_clap_comprehensive_suite.py and other team examples for setting up sequential or parallel agent workflows.
242
+
243
+ # MCP Integration: Check examples/test_clap_comprehensive_suite.py (ensure corresponding MCP servers from examples/simple_mcp.py etc. are running).
244
+
245
+ # Other LLM Services (Groq, Google Gemini , Ollama): Modify the Quick Starts to use GroqService or GoogleOpenAICompatService (ensure API keys are set).
246
+
247
+ # Different Vector Stores & Embedding Functions: Experiment with ChromaStore, QdrantStore, SentenceTransformerEmbeddings, FastEmbedEmbeddings, and OllamaEmbeddings as shown in the comprehensive test suite.
248
+
249
+ License
250
+ This project is licensed under the terms of the Apache License 2.0. See the LICENSE file for details.
251
+
252
+
253
+
@@ -0,0 +1,27 @@
1
+ # CHANGELOG.md
2
+
3
+ ## [0.2.0] - 2025-05-16
4
+ ### Added
5
+ - RAG (Retrieval Augmented Generation) capabilities for `Agent` and `ToolAgent`.
6
+ - `VectorStoreInterface` for abstracting vector database interactions.
7
+ - `ChromaStore` implementation for ChromaDB.
8
+ - `QdrantStore` implementation for Qdrant (local mode, supporting custom EFs and fastembed wrapper).
9
+ - `EmbeddingFunctionInterface` and concrete implementations:
10
+ - `SentenceTransformerEmbeddings`
11
+ - `OllamaEmbeddings`
12
+ - `FastEmbedEmbeddings`
13
+ - `Ollama Compatibility` Now run Ollama models locally (both embedding and chat).
14
+ - PDF and CSV loading utilities in `rag_utils`.
15
+ - Argument type coercion in `Tool.run()` for robustness.
16
+
17
+ ### Changed
18
+ - `ToolAgent` and `Agent` now require `llm_service` and `model` to be explicitly passed during initialization.
19
+ - Refined prompts for `ReactAgent` for better tool usage and RAG.
20
+ - Improved error handling and logging in various components.
21
+
22
+ ### Fixed
23
+ - Resolved various import errors and `NameError` issues in examples and core files.
24
+ - Fixed argument type mismatches for LLM tool calls.
25
+
26
+ ## [0.1.1] - 2025-04-19
27
+ - Initial release with core agent patterns.