Skip to content

About

Framework for developing adversarial multi-agent LLM systems where agents engage in reasoning, debate, and attack-defense scenarios, inspired by emerging research on vulnerabilities and robustness in multi-agent AI systems.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Adversarial Multi-Agent Reasoning Library

A modular Python library for structured adversarial agentic reasoning with multiple independent agents, RAG integration, and Chain-of-Thought data generation.

Features

  • Multiple Independent Agents: Each agent has unique prompts, perspectives, and optional RAG sources
  • Structured Adversarial Critique: Agents critique each other's answers across logical, factual, and completeness dimensions
  • Evaluator Synthesis: Final judge agent synthesizes the best elements into a refined verdict
  • RAG Integration: FAISS-based vector storage for document retrieval (PDF, TXT, MD)
  • Agent Memory: Configurable conversation history per agent or shared memory pools
  • COT Data Generation: Capture deliberation process for Chain-of-Thought training data

Architecture

Query → Independent Agents → Argument Layer → Evaluator → Verdict
         (with RAG)          (Critiques)      (Synthesis)

Key Principles

  1. Independence before interaction: Agents generate answers in isolation
  2. Structured argumentation: Constrained, role-based critique formats
  3. Asymmetric information flow: Only evaluator sees all answers and critiques
  4. Knowledge grounding: Each agent can use its own Content DB and Local RAG

Installation

# Clone the repository
git clone <repository-url>
cd talecom_AI

# Install dependencies
pip install -r requirements.txt

Dependencies

  • openai>=1.0.0 - LLM client
  • pydantic>=2.0.0 - Data validation
  • faiss-cpu>=1.7.4 - Vector storage
  • sentence-transformers>=2.2.0 - Embeddings
  • PyPDF2>=3.0.0 - PDF processing
  • pandas>=2.0.0 - Data processing (for COT export)
  • pyarrow>=10.0.0 - Parquet support

Quick Start

Basic Usage

from src.core import Agent, infer, Argument

# Configuration
LLM_PARAMS = {
    "modelName": "Qwen/Qwen2.5-7B-Instruct",
    "url": "http://127.0.0.1:8010/v1",
    "apiKey": "EMPTY"
}

# Create agents
AGENT_1 = Agent(
    prompt="You are a conservative analyst...",
    source_files=["docs/report.pdf"],  # Optional RAG
    llm_params=LLM_PARAMS,
    memory=True  # Enable conversation memory
)

AGENT_2 = Agent(
    prompt="You are an optimistic strategist...",
    llm_params=LLM_PARAMS,
    memory=True
)

AGENTS = [AGENT_1, AGENT_2]

# Phase 1: Independent answers
query = "Should we migrate to microservices?"
level_1_results = infer(AGENTS, query)

# Phase 2: Argumentation
ARGUMENT_INSTRUCTION = "Critique each other's answers..."
argument_level = Argument(ARGUMENT_INSTRUCTION, AGENTS, level_1_results)

# Phase 3: Judge evaluation
JUDGE = Agent(
    prompt="You are the final judge...",
    llm_params=LLM_PARAMS,
    agenttype='judge'
)

final_answer = infer([JUDGE], argument_level)
print(final_answer[0].answer)

With RAG Sources

# Agent with document sources
agent = Agent(
    prompt="You are a domain expert...",
    source_files=[
        "docs/technical_spec.pdf",
        "docs/case_studies.txt",
        "docs/notes.md"
    ],
    llm_params=LLM_PARAMS,
    memory=True
)

With Shared Memory

from src.core import SharedMemory

# Create shared memory pool
shared = SharedMemory()

agent_1 = Agent(
    prompt="You are a researcher...",
    llm_params=LLM_PARAMS,
    shared_memory=shared  # Agents share memory
)

agent_2 = Agent(
    prompt="You are a reviewer...",
    llm_params=LLM_PARAMS,
    shared_memory=shared  # Same shared memory
)

Project Structure

talecom_AI/
├── main.py                    # Main pipeline example
├── generate_cot_data.py      # COT data generation example
├── requirements.txt           # Dependencies
├── README.md                  # This file
└── src/
    ├── core/                  # Simplified agent API
    │   ├── agent.py           # Agent class
    │   ├── inference.py       # infer() function
    │   ├── argument.py        # Argument class
    │   └── memory.py          # Memory system
    ├── cot/                   # COT data generation
    │   ├── collector.py       # Data collection
    │   ├── formatter.py       # Data formatting
    │   └── exporter.py        # Export to JSONL/JSON/Parquet
    ├── agents/                # Advanced agent implementations
    ├── RAG/                   # RAG components
    │   ├── document_loader.py
    │   ├── chunker.py
    │   ├── embedder.py
    │   └── faiss_store.py
    ├── prompts/               # Prompt templates
    ├── pipeline/              # Pipeline orchestration
    └── schemas/               # Data models

Examples

Example 1: Simple Multi-Agent Deliberation

See main.py for a complete example with:

  • 4 agents with different perspectives
  • Structured argumentation phase
  • Final judge synthesis

Example 2: COT Data Generation

See generate_cot_data.py for generating Chain-of-Thought training data:

from src.cot import COTCollector, COTExporter

collector = COTCollector(model_name="Qwen/Qwen2.5-7B-Instruct")

# Run pipeline and collect data
result = collector.run(AGENTS, query, ARGUMENT_INSTRUCTION, JUDGE)

# Export in all formats
COTExporter.export_all(
    records=collector.get_records(),
    output_dir="./cot_data/",
    formats=["jsonl", "json", "parquet"]
)

API Reference

Agent

Agent(
    prompt: str,                    # System prompt
    llm_params: dict,               # LLM configuration
    source_files: list[str] = None, # RAG source files
    memory: bool = False,            # Enable memory
    shared_memory: SharedMemory = None,  # Use shared memory
    agenttype: str = "default",     # Agent type
    name: str = None,               # Agent name
)

infer()

results = infer(
    agents: list[Agent],
    query: Union[str, InferenceResults, ArgumentResult],
    additional_context: str = "",
    verbose: bool = False
) -> InferenceResults

Argument

argument = Argument(
    instruction: str,              # Argumentation rules
    agents: list[Agent],
    previous_results: InferenceResults,
    verbose: bool = False
)

Supported File Formats

RAG Sources

  • PDF: .pdf files (requires PyPDF2)
  • Text: .txt files
  • Markdown: .md, .markdown files

COT Export Formats

  • JSONL: One JSON object per line (ideal for fine-tuning)
  • JSON: Structured JSON files (human-readable)
  • Parquet: Columnar format (efficient for large datasets)

Configuration

LLM Setup

The library works with any OpenAI-compatible API. For local models:

# Using vLLM
python -m vllm.entrypoints.api_server \
    --model Qwen/Qwen2.5-7B-Instruct \
    --port 8010

Then configure:

LLM_PARAMS = {
    "modelName": "Qwen/Qwen2.5-7B-Instruct",
    "url": "http://127.0.0.1:8010/v1",
    "apiKey": "EMPTY"
}

Advanced Usage

Custom Agent Types

# Judge agent
judge = Agent(
    prompt="You are the final judge...",
    llm_params=LLM_PARAMS,
    agenttype='judge'
)

# Critic agent
critic = Agent(
    prompt="You are a logical critic...",
    llm_params=LLM_PARAMS,
    agenttype='critic'
)

RAG Configuration

from src.RAG import FAISSStore, DocumentLoader, TextChunker

# Custom RAG setup
loader = DocumentLoader()
documents = loader.load_directory("./docs/")

chunker = TextChunker(chunk_size=1000, chunk_overlap=200)
chunks = []
for doc in documents:
    chunks.extend(chunker.chunk_text(doc.content, source=doc.source))

store = FAISSStore(store_id="custom")
store.add_chunks(chunks)

# Use with agent
agent = Agent(
    prompt="...",
    llm_params=LLM_PARAMS,
    rag_store=store  # Use pre-built store
)

Contributing

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

License

[Add your license here]

Citation

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

@software{adversarial_agents,
  title = {Adversarial Multi-Agent Reasoning Library},
  author = {Your Name},
  year = {2024},
  url = {https://github.com/yourusername/talecom_AI}
}

Acknowledgments

  • Inspired by debate-style alignment and reviewer-author workflows
  • Built on OpenAI-compatible APIs and FAISS vector storage

About

Framework for developing adversarial multi-agent LLM systems where agents engage in reasoning, debate, and attack-defense scenarios, inspired by emerging research on vulnerabilities and robustness in multi-agent AI systems.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages