Physics question processing library and CLI - classification, LaTeX extraction, variant generation
Project description
VBAgent
A multi-agent library and CLI for processing physics, chemistry, and mathematics question images. Supports classification, LaTeX extraction, TikZ diagram generation, solution generation, variant creation, paper orchestration, and LaTeX compilation.
๐ Documentation | ๐ Issues | ๐ฌ Discussions
Installation
pip install -e ".[dev]"
Requirements
- Python 3.12+
- API key for your provider (set as env variable)
- For compilation:
pdflatex(TeX Live or MacTeX)
Supported Providers
| Provider | Env Variable | Models |
|---|---|---|
| OpenAI | OPENAI_API_KEY |
gpt-5.4, gpt-5.4-mini, gpt-5.2, gpt-5.1, gpt-5.1-codex |
| xAI | XAI_API_KEY |
grok-4, grok-4-1-fast-reasoning, grok-3, grok-3-mini |
GOOGLE_API_KEY |
gemini-2.5-pro, gemini-2.5-flash, gemini-3-flash-preview |
Default Models (OpenAI)
| Role | Model |
|---|---|
| Classification, scanning, checking | gpt-5.4-mini |
| Generation (idea, variant, alternate, solution, tikz, fbd) | gpt-5.4 |
Switch provider or model easily:
vbagent config provider xai # Switch to xAI
vbagent config provider google # Switch to Google
vbagent config provider openai # Back to OpenAI
vbagent config set solution -m gpt-5.2 # Override solution model
vbagent config set tikz -m gpt-5.4 # Override tikz model
vbagent config set default -m gpt-5.4 # Change global default
CLI Usage
Quick Start
vbagent init # Initialize workspace config
vbagent scan -i question.png -o out.tex # Extract LaTeX
vbagent classify -i question.png # Classify question type
vbagent tikz -i diagram.png -o diag.tex # Generate TikZ
vbagent run -i question.png # Full pipeline
Commands
| Section | Command | Description |
|---|---|---|
| Core | run |
Full pipeline: classify โ scan โ tikz โ solve |
| Core | scan |
Extract LaTeX from question image |
| Core | classify |
Classify question type |
| Core | batch |
Batch process multiple images with resume |
| Generate | tikz |
Generate TikZ/PGF diagrams |
| Generate | fbd |
Free body diagram generation |
| Generate | idea |
Extract physics concepts |
| Generate | alternate |
Generate alternate solutions |
| Generate | variant |
Generate problem variants |
| Generate | convert |
Convert between question formats |
| Quality | check |
QA review with interactive approval |
| Quality | compile |
Compile LaTeX to PDF |
| Manage | init |
Initialize workspace config |
| Manage | config |
Configure models, providers, settings |
| Manage | ref |
Manage reference context files |
| Manage | cache |
Cache management |
| Manage | db |
SQLite question bank |
| Manage | metadata |
Question bank metadata |
| Manage | export |
Export LaTeX (flat, structured, project) |
| Manage | dpp |
Daily Practice Problem sets |
| Manage | util |
File utilities (rename, count, clean) |
| Manage | extans |
Extract answers from LaTeX |
| Manage | screenshot |
Screenshot utilities |
| Interface | chat |
Interactive conversational interface |
| Interface | mcp |
MCP server for external agents |
| Paper | paper |
Paper orchestration (init, generate, solve, hint, compile, export) |
Paper Orchestrator
End-to-end paper generation workflow:
# Initialize a paper project
vbagent paper init physics --title "JEE Advanced 2025" --problems 4
# Generate problems from syllabus topics
vbagent paper generate /path/to/paper/
# Generate solutions for all problems
vbagent paper solve /path/to/paper/
# Generate hints
vbagent paper hint /path/to/paper/
# Compile to main.tex (stitches problems + solutions + hints + ideas + remarks)
vbagent paper compile /path/to/paper/
# Compile only solutions
vbagent paper compile /path/to/paper/ --only solutions
# Compile only hints
vbagent paper compile /path/to/paper/ --only hints
# Export zip for Overleaf
vbagent paper export /path/to/paper/
Paper directory structure:
paper_dir/
โโโ manifest.yaml # Paper config (subject, title, problems)
โโโ main.tex # Compiled output
โโโ scans/ # Per-problem .tex files (problem + solution + hint + idea + remark)
โ โโโ Problem_1.tex
โ โโโ Problem_2.tex
โ โโโ ...
โโโ solutions/ # Raw solution .tex files
โโโ hints/ # Raw hint .tex files
โโโ paper_export.zip # Overleaf-ready zip
Configuration
vbagent config show # Show all agent configs
vbagent config models # List available models
vbagent config provider # Show current provider
vbagent config provider xai # Switch to xAI (auto-applies model group)
vbagent config provider openai # Switch back to OpenAI
vbagent config set scanner -m gpt-5.4 # Override scanner model
vbagent config set default -m gpt-5.4 # Change global default
vbagent config model-group # List all model groups
vbagent config model-group openai # Apply OpenAI model group
vbagent config subject chemistry # Set subject
vbagent config debug on # Enable debug mode
vbagent config reset # Reset to defaults
Config hierarchy: global (~/.config/vbagent/models.json) โ workspace (.vbagent.json).
Supported Question Types
mcq_scโ MCQ Single Correctmcq_mcโ MCQ Multiple Correctassertion_reasonโ Assertion-Reasonmatchโ Match the Following (matrix match with codes)passageโ Passage/Comprehension (paragraph MCQ)integerโ Integer type (\ansint{N})subjectiveโ Subjective/Numerical
Project Structure
vbagent/
โโโ __init__.py # Public API with lazy imports
โโโ config.py # Configuration (models, providers, subjects)
โโโ compile.py # LaTeX compilation, validation, verbose debug
โโโ cache.py # Pipeline cache (solutions, hints, problems)
โโโ tex.py # TeX formatting utilities (format_tex, center_wrap_tikz)
โ
โโโ cli/ # CLI commands (Click-based, lazy-loaded)
โ โโโ main.py # Entry point with SectionedGroup
โ โโโ common.py # Shared utilities (panels, prompts, formatting)
โ โโโ core/
โ โ โโโ init.py # Workspace initialization
โ โ โโโ classify.py # Classification command
โ โ โโโ scan.py # LaTeX extraction command
โ โ โโโ process.py # Full pipeline command
โ โ โโโ batch.py # Batch processing command
โ โโโ generation/
โ โ โโโ tikz.py # TikZ generation command
โ โ โโโ fbd.py # FBD generation command
โ โ โโโ idea.py # Concept extraction command
โ โ โโโ alternate.py # Alternate solutions command
โ โ โโโ variant.py # Variant generation command
โ โ โโโ convert.py # Format conversion command
โ โโโ quality/
โ โ โโโ check.py # QA review command
โ โโโ compilation/
โ โ โโโ compile_main.py # LaTeX compile command + preamble
โ โโโ management/
โ โ โโโ config.py # Config management (provider, model-group, set)
โ โ โโโ ref.py # Reference management
โ โ โโโ db.py # Database management
โ โ โโโ metadata.py # Metadata management
โ โ โโโ export.py # Export command
โ โ โโโ dpp.py # DPP command
โ โ โโโ extans.py # Answer extraction
โ โ โโโ screenshot.py # Screenshot utilities
โ โ โโโ util.py # File utilities
โ โโโ cache/
โ โ โโโ cache_commands.py # Cache management commands
โ โโโ interfaces/
โ โ โโโ chat.py # Chat interface
โ โ โโโ mcp.py # MCP server
โ โ โโโ ui.py # UI helpers
โ โโโ paper/
โ โโโ paper_commands.py # Paper orchestrator CLI (init, generate, solve, hint, compile, export)
โ
โโโ agents/ # AI agent implementations
โ โโโ base.py # Base agent (create, run, encode image)
โ โโโ classifier.py # Question type classifier (v1)
โ โโโ classification/ # Multi-agent classification system
โ โ โโโ unified_classifier.py # Unified classifier
โ โ โโโ image_classifier.py # Image classification
โ โ โโโ diagram_analyzer.py # Diagram analysis
โ โ โโโ difficulty_assessor.py # Difficulty assessment
โ โ โโโ latex_classifier.py # LaTeX classification
โ โ โโโ idea_generator.py # Idea-to-problem generator
โ โ โโโ problem_combiner.py # Multi-problem combiner
โ โ โโโ taxonomy_classifier.py # Taxonomy classification
โ โ โโโ subject_detector.py # Subject auto-detection
โ โ โโโ schema_builder.py # Schema builder
โ โโโ content_generation/
โ โ โโโ scanner.py # LaTeX extraction agent
โ โ โโโ alternate.py # Alternate solution agent
โ โ โโโ converter.py # Format converter agent
โ โ โโโ idea.py # Concept extractor agent
โ โ โโโ solution/
โ โ โโโ __init__.py # Solution agent (routes by subject ร question_type)
โ โโโ diagram/ # TikZ diagram agents
โ โ โโโ base.py # Base diagram agent (600s timeout, style discipline)
โ โ โโโ tikz.py # Generic TikZ agent
โ โ โโโ tikz_router.py # TikZ agent routing
โ โ โโโ tikz_checker.py # TikZ validation agent
โ โ โโโ mcq_option_coordinator.py # MCQ option diagram coordinator
โ โ โโโ physics/
โ โ โ โโโ fbd.py # Free body diagram
โ โ โ โโโ circuit.py # Circuit diagram
โ โ โ โโโ graph.py # Physics graph
โ โ โ โโโ optics.py # Optics diagram
โ โ โโโ chemistry/
โ โ โ โโโ organic_structure.py # Organic structure
โ โ โ โโโ organic_orchestrator.py # Organic multi-step orchestrator
โ โ โ โโโ organic_simple.py # Simple organic
โ โ โ โโโ organic_complex.py # Complex organic
โ โ โ โโโ organic_functional.py # Functional group
โ โ โ โโโ organic_mechanism.py # Reaction mechanism
โ โ โ โโโ organic_multistep.py # Multi-step synthesis
โ โ โ โโโ organic_stereo.py # Stereochemistry
โ โ โ โโโ chemical_equation.py # Chemical equation
โ โ โ โโโ energy_diagram.py # Energy diagram
โ โ โ โโโ lewis_structure.py # Lewis structure
โ โ โ โโโ orbital.py # Orbital diagram
โ โ โ โโโ reaction_mechanism.py # Reaction mechanism
โ โ โโโ mathematics/
โ โ โโโ coordinate_geometry.py # Coordinate geometry
โ โ โโโ function_graph.py # Function graph
โ โ โโโ geometric_figure.py # Geometric figure
โ โ โโโ number_line.py # Number line
โ โ โโโ venn_diagram.py # Venn diagram
โ โโโ orchestration/
โ โ โโโ problem_orchestrator.py # Problem orchestrator
โ โ โโโ solution_orchestrator.py # Solution orchestrator
โ โโโ quality/
โ โ โโโ base.py # Base quality agent
โ โ โโโ reviewer.py # QA reviewer
โ โ โโโ solution_checker.py # Solution checker
โ โ โโโ grammar_checker.py # Grammar checker
โ โ โโโ clarity_checker.py # Clarity checker
โ โ โโโ format_checker.py # Format checker
โ โ โโโ latex_fixer.py # LaTeX fixer
โ โโโ variants/
โ โ โโโ variant.py # Single variant generator
โ โ โโโ cross_topic.py # Cross-topic variant
โ โ โโโ multi_context_variant.py # Multi-context variant
โ โโโ selection/
โ โ โโโ selector.py # Problem selector
โ โโโ metadata/
โ โโโ enricher.py # Metadata enricher
โ
โโโ prompts/ # LLM prompt templates
โ โโโ classification/
โ โ โโโ classifier.py # Base classifier prompt
โ โ โโโ unified_classifier.py # Unified classifier prompt
โ โ โโโ diagram_analyzer.py # Diagram analyzer prompt
โ โ โโโ idea_generator.py # Idea generator prompt
โ โ โโโ problem_combiner.py # Problem combiner prompt
โ โ โโโ question_types.py # Question type definitions
โ โ โโโ taxonomy.py # Taxonomy definitions
โ โโโ content_generation/
โ โ โโโ alternate.py # Alternate solution prompt
โ โ โโโ converter.py # Converter prompt
โ โ โโโ idea.py # Idea extraction prompt
โ โ โโโ scanner/ # Scanner prompts (per subject ร question type)
โ โ โ โโโ _shared.py # Shared scanner rules
โ โ โ โโโ physics/
โ โ โ โ โโโ common.py # Physics common rules
โ โ โ โ โโโ formatting_rules.py # Physics formatting
โ โ โ โ โโโ mcq_sc.py, mcq_mc.py, subjective.py
โ โ โ โ โโโ assertion_reason.py, match.py, passage.py
โ โ โ โ โโโ problem_only.py, solution_only.py
โ โ โ โ โโโ __init__.py # Router
โ โ โ โโโ chemistry/ # (same structure as physics)
โ โ โ โโโ mathematics/ # (same structure as physics)
โ โ โโโ solution/ # Solution prompts (per subject ร question type)
โ โ โโโ __init__.py # Top-level router
โ โ โโโ physics/
โ โ โ โโโ common.py # Physics solution rules
โ โ โ โโโ mcq_sc.py, mcq_mc.py, subjective.py
โ โ โ โโโ assertion_reason.py, match.py, passage.py
โ โ โ โโโ __init__.py # Router
โ โ โโโ chemistry/ # (same structure as physics)
โ โ โโโ mathematics/ # (same structure as physics)
โ โโโ diagram/
โ โ โโโ _style_discipline.py # TikZ style rules (no colors, no inline overrides)
โ โ โโโ tikz_checker.py # TikZ checker prompt
โ โ โโโ physics/
โ โ โ โโโ fbd.py, circuit.py, graph.py, optics.py, generic.py
โ โ โ โโโ __init__.py
โ โ โโโ chemistry/
โ โ โ โโโ organic_structure.py, organic_simple.py, organic_complex.py
โ โ โ โโโ organic_functional.py, organic_mechanism.py, organic_multistep.py
โ โ โ โโโ organic_stereo.py, chemical_equation.py, energy_diagram.py
โ โ โ โโโ lewis_structure.py, orbital.py, reaction_mechanism.py
โ โ โ โโโ __init__.py
โ โ โโโ mathematics/
โ โ โโโ coordinate_geometry.py, function_graph.py, geometric_figure.py
โ โ โโโ number_line.py, venn_diagram.py
โ โ โโโ __init__.py
โ โโโ quality/
โ โ โโโ reviewer.py, solution_checker.py, grammar_checker.py
โ โ โโโ clarity_checker.py, format_checker.py
โ โ โโโ __init__.py
โ โโโ variants/
โ โ โโโ numerical.py, context.py, conceptual.py
โ โ โโโ conceptual_calculus.py, cross_topic.py, multi_context.py
โ โ โโโ __init__.py
โ โโโ subjects/
โ โโโ __init__.py # Subject-specific context
โ
โโโ models/ # Pydantic data models
โ โโโ classification.py # Classification models
โ โโโ content.py # Content models
โ โโโ diagram.py # Diagram models
โ โโโ diff.py # Diff models
โ โโโ metadata.py # Metadata models
โ โโโ orchestration.py # Orchestration models
โ โโโ pipeline.py # Pipeline models
โ โโโ quality.py # Quality models
โ โโโ review.py # Review models
โ โโโ solution.py # Solution models
โ โโโ version_store.py # Version store models
โ โโโ workflow.py # Workflow models
โ
โโโ paper/ # Paper orchestrator
โ โโโ __init__.py
โ โโโ models.py # Paper data models
โ โโโ manifest.py # Manifest YAML handling
โ โโโ syllabus.py # Syllabus topic definitions
โ โโโ generator.py # Problem generation
โ โโโ orchestrator.py # Paper orchestrator (compile, export, assemble)
โ โโโ qa.py # Paper QA
โ
โโโ pipeline/ # Processing pipeline
โ โโโ __init__.py
โ โโโ io.py # Pipeline I/O
โ โโโ runner.py # Pipeline runner
โ โโโ stages.py # Pipeline stages
โ
โโโ database/ # SQLite question bank
โ โโโ store.py # QuestionDatabase
โ โโโ extractor.py # ContentExtractor
โ โโโ reconstructor.py # LaTeX reconstruction
โ โโโ metadata_helper.py # Agent metadata population
โ
โโโ references/ # Reference context management
โ โโโ store.py # Reference store
โ โโโ context.py # Context builder
โ โโโ tikz_store.py # TikZ reference store
โ โโโ samples/ # Sample references
โ โโโ physics/ # assertion_reason.tex, mcq_mc.tex, mcq_sc.tex, subjective.tex
โ โโโ chemistry/ # mcq_mc.tex, mcq_sc.tex, subjective.tex
โ โโโ mathematics/ # mcq_mc.tex, mcq_sc.tex, subjective.tex
โ
โโโ storage/ # Content storage
โ โโโ content_cache.py # Content cache
โ โโโ metadata_manager.py # Metadata manager
โ
โโโ orchestrator/ # Chat orchestrator
โ โโโ conversation.py # Conversation handler
โ โโโ tools.py # Tool definitions
โ โโโ tool_wrappers.py # Tool wrappers
โ
โโโ dpp/
โ โโโ builder.py # DPP builder
โ
โโโ export/
โ โโโ exporter.py # LaTeX exporter
โ
โโโ mcp/
โ โโโ server.py # MCP server
โ
โโโ metadata/
โ โโโ store.py # Metadata store
โ
โโโ templates/
โ โโโ agentic_context.py # CONTEXT.md generator
โ
โโโ ui/ # Terminal UI
โ โโโ components.py # UI components
โ โโโ logging.py # Logging
โ โโโ styles.py # Styles
โ โโโ tables.py # Tables
โ
โโโ utils/
โโโ formatting.py # Formatting utilities
โโโ latex.py # LaTeX utilities
tests/
โโโ agents/
โ โโโ classification/ # test_classification.py, test_database.py, test_models.py, test_router.py
โ โโโ content_generation/ # test_alternate.py, test_converter.py, test_idea.py, test_scanner.py
โ โโโ diagram/ # test_tikz.py
โ โโโ metadata/ # test_metadata.py
โ โโโ orchestration/ # test_orchestrator.py
โ โโโ quality/ # test_review.py
โ โโโ selection/ # test_selector.py
โ โโโ variants/ # test_variant.py
โโโ cli/
โ โโโ core/ # test_batch.py, test_process.py
โ โโโ interfaces/ # test_chat_cli.py, test_chat_interface.py, test_mcp_server.py
โ โโโ management/ # test_config.py, test_export_tools.py, test_export.py
โโโ integration/ # test_context.py, test_dpp_builder.py, test_import_performance.py, ...
โโโ models/ # test_version_store.py
โโโ paper/ # test_cli.py, test_generator.py, test_manifest.py, test_models.py, ...
โโโ ui/ # test_ui_components.py
โโโ utils/ # test_formatting.py, test_latex.py, test_tex_parser.py
LaTeX Compilation
The -c / --compile flag validates generated LaTeX by compiling with pdflatex. If compilation fails, the compile-fixer agent automatically attempts to fix errors (up to 2 retries).
Compile Preamble
fourier[upright]for fonts\everymath{\displaystyle}for display-style mathamsmath,amssymb,amsthm,mathtoolstikzwith libraries: calc, decorations, patterns, arrows.meta, positioning, shapes, intersections, angles, quotescircuitikz(american style),pgfplots(compat=1.18)tasks(MCQ options),enumitemmhchem,chemfig(chemistry only)- Auto-detected packages from
.texfile content
Environment Definitions
| Environment | Color | Symbol |
|---|---|---|
solution |
red | $\Rightarrow$ |
alternatesolution |
blue | $\Rrightarrow$ |
hint |
maroon | $\looparrowright$ |
idea |
violet | $\diamond$ |
remark |
teal | $\circ$ |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vbagent-0.3.6.tar.gz.
File metadata
- Download URL: vbagent-0.3.6.tar.gz
- Upload date:
- Size: 571.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.12 Darwin/25.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eeeec98eec357f717d6cc7cd511efc35607b25fac151d93fd564eb19f99ef88e
|
|
| MD5 |
389e64901debacd0d984d4f7bd7acb82
|
|
| BLAKE2b-256 |
6ab5ef3e6562bab6c90209e44b87f5c35e8ed75be90731635821b2ea6120897d
|
File details
Details for the file vbagent-0.3.6-py3-none-any.whl.
File metadata
- Download URL: vbagent-0.3.6-py3-none-any.whl
- Upload date:
- Size: 804.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.12 Darwin/25.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e49f7f1ac34aff4a0c9269526a2090653fbf1419aa760e079de5ff772318e2cd
|
|
| MD5 |
364f0d1289d732b243bebda389f4d9f2
|
|
| BLAKE2b-256 |
0eea1c90628b957b1a468d048cb863c5de52161b6a42f10321662736aa49c146
|