Skip to main content

Multi-agent System for Financal Knowledge Graph Construction using LangGraph

Project description

MA-FINKG: Multi-Agent Framework for Financial Knowledge Graph Construction from Unstructured Text

A multi-agent system based on LangGraph for constructing Knowledge Graphs from financial text documents. The system uses specialized agents to coordinate domain-specific ontology building, text processing, and knowledge extraction.

Features

  • Multi-Agent Architecture: Coordinated agents for different aspects of KG construction
  • Benchmarked on varity of datasets: Support for FIRE, NYT11, CoNLLpp, REFinD, and custom ontologies
  • Flexible Prompting: Specialized prompt sets optimized for different datasets
  • DSPy Integration: Optional optimization for improved extraction performance
  • Financial Focus: Specialized for financial text analysis and knowledge extraction

Installation

pip install ma-finkg

Or install from source:

git clone <repository-url>
cd financial_kg_system
pip install -e .

Quick Start

from ma_finkg import MA_FinKG

# Initialize with API key
kg = MA_FinKG(api_key="your-openrouter-key")

# Or set environment variable
import os
os.environ["OPENROUTER_API_KEY"] = "your-key"
kg = MA_FinKG()

# Generate knowledge graph
text = "Apple Inc. reported revenue of $95B in Q4 2023."
result = kg.generate(text)

# Access results
print(f"Found {len(result.entities)} entities and {len(result.triples)} relations")
print("Entities:", result.entities)
print("Relations:", result.triples)

Available Ontologies

FIRE (Default)

Financial dataset ontology with comprehensive financial entities and relations.

Entities: Action, BusinessUnit, Company, Date, Designation, FinancialEntity, GeopoliticalEntity, Location, Money, Person, Product, Quantity, Sector

Relations: ActionBuy, ActionSell, ActionMerge, Employeeof, Subsidiaryof, Value, Locatedin, etc. (18 total)

NYT11

General-purpose ontology based on the NYT dataset.

Entities: PER (Person), ORG (Organization), LOC (Location)

Relations: /people/person/place_of_birth, /business/company/founders, /location/country/capital, etc. (12 total)

Other Ontologies

  • CoNLLpp: Named Entity Recognition dataset ontology
  • REFinD: ReFiNED dataset ontology
  • Default: Generic financial ontology

Configuration Options

kg = MA_FinKG(
    model="openai/gpt-4o-mini",  # or "google/gemini-2.5-flash-lite"
    ontology="fire",             # "fire", "nyt11", "conllpp", "refind", "default"
    prompts="fire",              # matching prompt set
    use_dspy=False,              # True for optimized extraction
    api_key="your-key"           # OpenRouter API key
)

Multi-Agent Architecture

The system employs four specialized agents:

  1. KG Expert: Task coordinator that manages the overall KG construction process
  2. Domain Specific Expert: Builds domain-specific ontologies from input text
  3. Data Processing Expert: Performs lossless text cleaning and preparation
  4. Knowledge Extraction Expert: Orchestrates NER and RE sub-agents for entity and relation extraction

Command Line Usage

# Show help
ma-finkg --help
python -m ma_finkg --help

# Show version
ma-finkg --version
python -m ma_finkg --version

Requirements

  • Python 3.9+
  • langchain-core
  • langchain-openai
  • langgraph
  • dspy-ai
  • pydantic
  • pyyaml
  • json-repair

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Citation

If you use this software in your research, please cite:

@software{ma-finkg,
  title={MA-FinKG: Multi-Agent System for Financial Knowledge Graph Construction for Text},
  author={Abdel-Rahman Elzohairy},
  version={0.1.5},
  year={2025}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ma_finkg-0.1.5.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ma_finkg-0.1.5-py3-none-any.whl (52.5 kB view details)

Uploaded Python 3

File details

Details for the file ma_finkg-0.1.5.tar.gz.

File metadata

  • Download URL: ma_finkg-0.1.5.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for ma_finkg-0.1.5.tar.gz
Algorithm Hash digest
SHA256 80c8efcd44f778d3e1e3722547f2935a48a57b0f379470eb638c765bcf290ded
MD5 7c2b2f26fa8e10f4a03dd5088a160677
BLAKE2b-256 9700e4f865f8baf78f2a0f6e5b795c15bf55cd7eb441cbcd41a838402c9f9feb

See more details on using hashes here.

File details

Details for the file ma_finkg-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: ma_finkg-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 52.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for ma_finkg-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 84a6d43ebff7d95df6f28320c8fb69eace7861cac1359131ea9687242db88e23
MD5 f5f0cfc7bdc1792aa9b375214c4332a0
BLAKE2b-256 9809e25489f05031be0b38ad7e6400b3bf0ede208b7a0abd806cf54029fcf975

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page