Skip to content

examples: add AG2 multi-agent chat over private documents#2210

Open
faridun-ag2 wants to merge 2 commits intozylon-ai:mainfrom
faridun-ag2:add-ag2-multiagent-example
Open

examples: add AG2 multi-agent chat over private documents#2210
faridun-ag2 wants to merge 2 commits intozylon-ai:mainfrom
faridun-ag2:add-ag2-multiagent-example

Conversation

@faridun-ag2
Copy link
Copy Markdown

Description

Adds an example demonstrating AG2 multi-agent orchestration on top of PrivateGPT. Three specialized agents collaborate to analyze private documents using PrivateGPT's RAG API as a tool.

AG2 is an open-source multi-agent framework with 500K+ monthly PyPI downloads, 4,300+ GitHub stars, and 400+ contributors.

Architecture

User question → AG2 GroupChat → PrivateGPT API (localhost:8001)
  ├── Researcher: RAG queries with use_context=true
  ├── Analyst: follow-up queries to verify findings
  └── Writer: synthesizes final answer with source references

What it demonstrates

  • AG2 GroupChat with automatic speaker selection
  • PrivateGPT's /v1/chat/completions as a registered AG2 tool
  • Document-grounded multi-agent reasoning
  • Privacy-preserving architecture: retrieval is 100% local, reasoning can be local or external

Why multi-agent + private RAG

  • Single-query RAG can miss context. Multiple agents with different query strategies (broad search, targeted follow-ups) provide more thorough coverage.
  • The Researcher/Analyst/Writer pattern mirrors real document analysis workflows.

Files

  • examples/ag2_multiagent.py — standalone script, no changes to core PrivateGPT
  • examples/README.md — setup and usage guide

Testing

  • Script runs end-to-end with PrivateGPT server (mock mode)
  • Researcher agent calls PrivateGPT RAG and receives document-grounded responses with sources
  • Analyst agent asks follow-up queries for verification
  • Writer agent synthesizes findings and terminates conversation
  • Graceful error when PrivateGPT is not running
  • No hardcoded secrets
  • Passes Black, Ruff formatting

Add a standalone example demonstrating AG2 multi-agent orchestration
on top of PrivateGPT's OpenAI-compatible API. Three specialized agents
(Researcher, Analyst, Writer) collaborate to analyze private documents
using PrivateGPT's RAG pipeline as a registered tool.

No changes to core PrivateGPT code.
- Extract sources from choices[0].sources (PrivateGPT's actual response
  structure) instead of top-level sources field
- Set max_consecutive_auto_reply=10 so UserProxy relays tool results
  back to the group chat
- Add is_termination_msg to stop conversation after Writer says TERMINATE

Verified end-to-end with PrivateGPT mock mode + OpenAI GPT-4o-mini.
@faridun-ag2
Copy link
Copy Markdown
Author

Hey @imgarylai @Toad882 @atari2600tim !

This PR adds a standalone AG2 multi-agent example (examples/ directory only, zero changes to core PrivateGPT). It's been tested end-to-end against PrivateGPT in mock mode with GPT-4o-mini for agent reasoning — full details in the PR description.

Note on the failing pre-commit CI check: The failure is not related to this PR. It's caused by a deprecated actions/upload-artifact@v3 in the repository's GitHub Actions workflow, which GitHub now auto-rejects:

Error: This request has been automatically failed because it uses a deprecated version of actions/upload-artifact: v3.

This affects all PRs on this repo. Upgrading to actions/upload-artifact@v4 in .github/workflows/ should fix it.

Would appreciate a review when you get a chance. Happy to adjust anything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant