# Can Semantica Be Used with Agent Frameworks? LangChain & CrewAI Integration Guide

> Explore how to use Semantica with agent frameworks like LangChain and CrewAI. Discover seamless integration with adapter modules for retrievers, vector stores, and agent tools.

- Repository: [Semantica /semantica](https://github.com/semantica-agi/semantica)
- Tags: how-to-guide
- Published: 2026-09-05

---

**Yes, Semantica provides first-class integrations for LangChain, LangGraph, and CrewAI through optional adapter modules that expose retrievers, vector stores, and agent tools.**

Semantica is a contextual knowledge graph and semantic search engine designed for AI applications. According to the `semantica-agi/semantica` source code, the repository ships with dedicated integration layers that let you drop Semantica's **GraphRAG capabilities** directly into popular Python agent frameworks—without forcing heavy dependencies on users who don't need them.

## How Semantica Integrates with Agent Frameworks

The integration architecture follows a **graceful degradation** pattern. Each framework module checks for availability before importing dependencies:

- **`LANGCHAIN_AVAILABLE`** – Set in [`integrations/langchain/__init__.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/langchain/__init__.py) after successful `import langchain_core`
- **`CREWAI_AVAILABLE`** – Managed in [`integrations/crewai/_availability.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/crewai/_availability.py)

When a framework is absent, Semantica classes remain importable but skip framework-specific functionality. When present, they register as fully compatible components.

## LangChain and LangGraph Integration

The LangChain integration (`integrations/langchain/`) provides four core components:

**`SemanticaRetriever`** – A `BaseRetriever` implementing GraphRAG-style retrieval. It seeds results via `HybridSearch` then expands via `ContextGraph.get_neighbors()` for multi-hop graph walks.

**`SemanticaVectorStore`** – A `VectorStore` adapter forwarding Retrieval-QA and LCEL calls to Semantica's hybrid search backend.

**`SemanticaKGTool`** – A `BaseTool` for direct knowledge graph queries from LangChain agents.

**`SemanticaDecisionTool`** – Exposes Semantica's decision-log API for agents to query or update decisions.

### LangChain Usage Example

```python

# pip install semantica[langchain]

from semantica.context import ContextGraph
from semantica.vector_store import HybridSearch
from integrations.langchain import (
    SemanticaRetriever,
    SemanticaVectorStore,
    SemanticaKGTool,
    SemanticaDecisionTool,
)

# Build core components

graph = ContextGraph(...)
hybrid = HybridSearch(...)

# Retrieval-QA chain

from langchain.chains import RetrievalQA
from langchain.llms import OpenAI

retriever = SemanticaRetriever(graph=graph, hybrid=hybrid, hops=2, top_k=5)

qa = RetrievalQA.from_chain_type(
    llm=OpenAI(),
    retriever=retriever,
)
print(qa.run("What are the key risks for project X?"))

# LangChain agent with tools

from langchain.agents import initialize_agent, AgentType

agent = initialize_agent(
    tools=[
        SemanticaKGTool(graph=graph),
        SemanticaDecisionTool(),
    ],
    llm=OpenAI(),
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
)
print(agent.run("Summarize the latest decisions about data governance."))

```

The retriever implementation in [`integrations/langchain/retriever.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/langchain/retriever.py) (lines 96-124) handles the GraphRAG pipeline: vector search seeds, graph expansion, and document wrapping via `_get_document()`.

## CrewAI Integration

The CrewAI integration (`integrations/crewai/`) exposes three specialized components:

**`SemanticaKGTool`** – `BaseTool` wrapping `ContextGraph` for agent reasoning.

**`SemanticaDecisionTool`** – `BaseTool` exposing `DecisionVectorMethods` for decision-log operations.

**`SemanticaKnowledgeSource`** – `BaseKnowledgeSource` delivering graph knowledge directly to CrewAI crews.

### CrewAI Usage Example

```python

# pip install semantica[crewai]

from semantica.context import ContextGraph
from semantica.vector_store import HybridSearch
from integrations.crewai import (
    SemanticaKGTool,
    SemanticaDecisionTool,
    SemanticaKnowledgeSource,
)

graph = ContextGraph(...)
hybrid = HybridSearch(...)

kg_tool = SemanticaKGTool(graph=graph)
decision_tool = SemanticaDecisionTool(graph=graph)
knowledge_source = SemanticaKnowledgeSource(graph=graph, hybrid=hybrid)

# Build CrewAI crew

from crewai import Crew, Agent, Task

researcher = Agent(
    role="Researcher",
    goal="Gather up-to-date information from the knowledge graph",
    tools=[kg_tool, decision_tool],
    verbose=True,
)

task = Task(
    description="Explain the current status of the AI roadmap.",
    expected_output="A concise summary in markdown.",
)

crew = Crew(
    agents=[researcher],
    tasks=[task],
    knowledge_source=knowledge_source,
)

result = crew.kickoff()
print(result)

```

Tool implementations in [`integrations/crewai/kg_tool.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/crewai/kg_tool.py) and [`decision_tool.py`](https://github.com/semantica-agi/semantica/blob/main/decision_tool.py) provide simple `run()` methods that forward to Semantica's core APIs.

## Internal Architecture: How GraphRAG Works in Agents

The integration layers are thin wrappers around Semantica's core. The retrieval pipeline follows four steps:

1. **Seed via hybrid search** – `HybridSearch` in [`semantica/vector_store/hybrid_search.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/vector_store/hybrid_search.py) returns top-k vector matches
2. **Graph expansion** – `ContextGraph.get_neighbors(node_id, hops=self.hops)` walks outgoing edges
3. **Result enrichment** – Multi-hop context is aggregated into coherent result sets
4. **Framework adaptation** – `_get_document()` wraps output as LangChain `Document` or plain dict

Because tools expose simple callable interfaces, any agent framework accepting retrievers or tools can integrate with minimal boilerplate.

## Key Source Files

| Component | Path |
|-----------|------|
| LangChain public API | [`integrations/langchain/__init__.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/langchain/__init__.py) |
| GraphRAG retriever | [`integrations/langchain/retriever.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/langchain/retriever.py) |
| Vector store adapter | [`integrations/langchain/vectorstore.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/langchain/vectorstore.py) |
| LangChain tools | [`integrations/langchain/tools.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/langchain/tools.py) |
| CrewAI public API | [`integrations/crewai/__init__.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/crewai/__init__.py) |
| CrewAI KG tool | [`integrations/crewai/kg_tool.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/crewai/kg_tool.py) |
| CrewAI decision tool | [`integrations/crewai/decision_tool.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/crewai/decision_tool.py) |
| CrewAI knowledge source | [`integrations/crewai/knowledge_source.py`](https://github.com/semantica-agi/semantica/blob/main/integrations/crewai/knowledge_source.py) |
| Core graph engine | [`semantica/context.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/context.py) |
| Hybrid search | [`semantica/vector_store/hybrid_search.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/vector_store/hybrid_search.py) |

## Summary

- **Semantica integrates natively with LangChain/LangGraph and CrewAI** through optional, gracefully-degrading adapter modules
- **Four LangChain components**: `SemanticaRetriever`, `SemanticaVectorStore`, `SemanticaKGTool`, `SemanticaDecisionTool`
- **Three CrewAI components**: `SemanticaKGTool`, `SemanticaDecisionTool`, `SemanticaKnowledgeSource`
- **GraphRAG retrieval** combines vector search seeding with multi-hop graph expansion via `ContextGraph.get_neighbors()`
- **Zero forced dependencies** – framework integrations only activate when target libraries are installed

## Frequently Asked Questions

### How do I install Semantica with LangChain support?

Install the optional dependency group: `pip install semantica[langchain]`. This pulls `langchain-core` and registers the LangChain-specific classes without affecting core Semantica functionality.

### Can I use Semantica with CrewAI and LangChain in the same project?

Yes. The integration modules are independent. Installing both `semantica[langchain]` and `semantica[crewai]` lets you import from both `integrations.langchain` and `integrations.crewai` simultaneously, sharing the same `ContextGraph` and `HybridSearch` instances across frameworks.

### What happens if I import Semantica without the framework installed?

The modules remain importable but set their availability flags (`LANGCHAIN_AVAILABLE`, `CREWAI_AVAILABLE`) to `False`. Core Semantica classes like `ContextGraph` and `HybridSearch` function normally; only the framework adapters disable themselves.

### Is Semantica compatible with LangGraph specifically?

Yes. `SemanticaRetriever` and `SemanticaVectorStore` implement standard LangChain interfaces that LangGraph's LCEL patterns consume directly. The retriever's GraphRAG expansion happens transparently during each retrieval call.