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

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)

Default (Default)

Generic financial ontology used when no specific dataset is specified.

Other Ontologies

  • CoNLLpp: Named Entity Recognition dataset ontology
  • REFinD: ReFiNED dataset ontology

Configuration Options

kg = MA_FinKG(
    model="openai/gpt-4o-mini",  # or "google/gemini-2.5-flash-lite"
    ontology="default",          # "default" (default), "fire", "nyt11", "conllpp", "refind"
    prompts="default",           # "default" (default), 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.6.tar.gz (34.2 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.6-py3-none-any.whl (52.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ma_finkg-0.1.6.tar.gz
Algorithm Hash digest
SHA256 674a0ce0e4cc1e05576ccc6c5c4f232eecd1fb6046dbb5573289286200a642b6
MD5 530dbca9f5d1a85681c2387093f870a3
BLAKE2b-256 38c0bea202d4134596aea1603263528bc9cc6623b108bca1a68bdfb275a05ab0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ma_finkg-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c0b02394a1b64c0a35b50d44de388ee5b868ea570bdb16afc6ea8efea8743f30
MD5 b467a73a2c54594c013156243437305a
BLAKE2b-256 0904ed330311c802c6caf5ff4155f3c6c04cdcb4cf5ea9add527e76654f694fa

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