Morphik Agent
Intelligent agentic query processing with autonomous tool usage
The Morphik Agent is an intelligent assistant that autonomously uses various tools to answer complex queries and perform sophisticated analysis tasks. Unlike traditional retrieval-augmented generation (RAG) systems that follow a fixed pipeline, the agent can dynamically decide which tools to use, execute code, analyze documents, and even save insights to memory for future reference.
How It Works
Architecture Overview
The Morphik Agent operates using a function-calling LLM (Large Language Model) that can:
- Analyze the Query: Understand what the user is asking for
- Plan Tool Usage: Decide which tools are needed to answer the query
- Execute Tools: Call the appropriate tools with the right parameters
- Process Results: Analyze tool outputs and decide if more tools are needed
- Generate Response: Provide a comprehensive answer with structured content
Tool Ecosystem
The agent has access to eight core tools:
Document Operations
retrieve_chunks
: Search and retrieve relevant text/image chunksretrieve_document
: Get full document content or metadatadocument_analyzer
: Extract entities, facts, summaries, sentimentlist_documents
: Discover available documents
Knowledge Operations
knowledge_graph_query
: Query entities, relationships, and pathslist_graphs
: Discover available knowledge graphs
Computation
execute_code
: Run Python code in a secure sandbox
Memory
save_to_memory
: Store insights for future queries
Key Capabilities
1. Multi-Step Analysis
The agent can break down complex requests into multiple steps:
2. Code Execution
The agent can write and execute Python code for calculations, data analysis, and visualization:
3. Knowledge Graph Exploration
The agent can navigate complex relationships in your data:
4. Memory and Context
The agent can remember important insights across queries:
Response Structure
The agent returns a rich, structured response with four components:
1. Final Response (response
)
The main textual answer to your query.
2. Tool History (tool_history
)
Complete audit trail of all tool executions:
3. Display Objects (display_objects
)
Structured content for rich presentation:
4. Sources (sources
)
Attribution for all referenced content:
When to Use the Agent
Choose agent_query
for:
✅ Complex Analysis Tasks
- Multi-step analysis requiring different tools
- Data analysis with calculations
- Research requiring document discovery
✅ Computation Requirements
- Statistical analysis
- Data visualization
- Mathematical calculations
✅ Knowledge Graph Exploration
- Relationship discovery
- Entity connection analysis
- Path finding between concepts
✅ Multi-Modal Content
- Analyzing both text and images
- Extracting information from charts/diagrams
✅ Memory-Dependent Tasks
- Building on previous analysis
- Maintaining context across queries
Choose regular query
for:
✅ Simple Q&A
- Direct questions about document content
- Quick information retrieval
- Straightforward fact-finding
✅ Performance-Critical Applications
- When speed is more important than depth
- Simple document lookup scenarios
Best Practices
1. Query Design
Be Specific About Goals:
Include Analysis Context:
2. Response Processing
Check Tool History for Understanding:
Use Display Objects for Rich Content:
3. Error Handling
4. Memory Usage
Performance Considerations
Response Time
- Agent queries typically take 10-60 seconds depending on complexity
- Each tool call adds processing time
- Complex code execution can extend response time
Cost Implications
- Uses more LLM tokens than regular queries
- Cloud deployments may have usage limits
- Tool execution (especially code) consumes additional resources
Context Window Management
- Very complex queries may hit LLM context limits
- Agent automatically manages context but extremely long sessions may fail
- Consider breaking very complex tasks into smaller queries
Security Model
Code Execution Sandbox
- Python code runs in a secure, isolated environment
- No access to file system or network
- Limited to approved libraries and functions
- Execution time limits prevent infinite loops
Data Access
- Agent respects same access controls as other Morphik operations
- Cannot access documents outside user’s permissions
- Memory storage follows same security model
Tool Limitations
- Tools cannot perform destructive operations
- No ability to modify or delete documents
- Read-only access to knowledge graphs
- Memory is scoped to user/session
Comparison with Traditional RAG
Aspect | Traditional RAG | Morphik Agent |
---|---|---|
Workflow | Fixed: Retrieve → Generate | Dynamic: Plan → Execute → Iterate |
Tool Access | None | Full tool ecosystem |
Computation | None | Python code execution |
Memory | Stateless | Persistent memory |
Response Format | Simple text | Structured with attribution |
Use Cases | Simple Q&A | Complex analysis |
Processing Time | Fast (seconds) | Moderate (tens of seconds) |
Cost | Lower | Higher |
Future Roadmap
The Morphik Agent will continue to evolve with:
- Additional Tools: Web search, API integrations, file operations
- Improved Planning: Better tool selection and optimization
- Enhanced Memory: Longer-term memory with better organization
- Custom Tools: User-defined tools and functions
- Multi-Agent Orchestration: Specialized agents for different domains
The agent represents a significant evolution from traditional RAG systems, enabling complex analytical workflows that were previously impossible with simple retrieval-based approaches.