Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions .github/workflows/pre-commit.yml

This file was deleted.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

An AI-powered agent library for answering questions about Invopop and GOBL documentation using LangChain and MCP (Model Context Protocol) servers.

It also has access to the following repositories:
- [gobl](https://github.com/invopop/gobl)
- [gobl.verifactu](https://github.com/invopop/gobl.verifactu)
- [gobl.fatturapa](https://github.com/invopop/gobl.fatturapa)
- [gobl.cfdi](https://github.com/invopop/gobl.cfdi)
- [gobl.ubl](https://github.com/invopop/gobl.ubl)
- [gobl.cii](https://github.com/invopop/gobl.cii)

## Features

- 🤖 **Intelligent Q&A**: Answers questions about Invopop and GOBL using advanced RAG
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Invopop Expert Configuration
llm:
provider: "openai"
model: "gpt-4.1-2025-04-14"
model: "gpt-4.1"
temperature: 0.1

opik:
Expand Down
27 changes: 22 additions & 5 deletions src/expert/agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Main agent implementation for Invopop Expert."""

import json
from datetime import datetime
from pathlib import Path

Expand All @@ -11,6 +12,15 @@

from .config import Config

AVAILABLE_REPOS = [
"invopop/gobl",
"invopop/gobl.verifactu",
"invopop/gobl.ubl",
"invopop/gobl.fatturapa",
"invopop/gobl.cfdi",
"invopop/gobl.cii",
]


class InvopopExpert:
"""Main agent class for Invopop Expert."""
Expand All @@ -22,6 +32,7 @@ def __init__(self, config: Config):
self.checkpointer = InMemorySaver()
self._load_prompts()
self.opik_config = None
self.mcp_client = None

def _load_prompts(self):
"""Load prompt templates from files."""
Expand All @@ -42,10 +53,10 @@ def _load_prompts(self):
async def setup(self):
"""Initialize the MCP client and create the agent."""
# Initialize the MultiServerMCPClient
client = MultiServerMCPClient(self.config.mcp_config)
self.mcp_client = MultiServerMCPClient(self.config.mcp_config)

# Get and rename tools
tools = await client.get_tools()
tools = await self.mcp_client.get_tools()
renamed_tools = []

for tool in tools:
Expand All @@ -62,10 +73,10 @@ async def setup(self):
new_description = self.gobl_code_description
new_schema = tool.args_schema.copy()
new_schema["properties"]["repoName"]["description"] = (
"This value will always be 'invopop/gobl'"
"This value will always be one of the following: " + ", ".join(AVAILABLE_REPOS)
)
new_schema["properties"]["question"]["description"] = (
"The question to ask about the invopop/gobl repo"
"The question to ask about the repo"
)
else:
continue
Expand All @@ -90,6 +101,7 @@ async def setup(self):
renamed_tools,
checkpointer=self.checkpointer,
prompt=self.system_prompt,
version="v2",
)

# Store Opik configuration if configured
Expand Down Expand Up @@ -148,8 +160,13 @@ async def get_response(self, user_input: str, thread_id: str) -> str:
tool_call["function"]["arguments"],
)
elif func_name == "gobl_code_ask_question":
args = tool_call["function"]["arguments"]
if isinstance(args, str):
args = json.loads(args)

repo_name = args.get("repoName", "unknown")
print(
"🔍 Searching invopop/gobl repo:",
f"🔍 Searching {repo_name} repo:",
tool_call["function"]["arguments"],
)
# Update the final message content
Expand Down
73 changes: 62 additions & 11 deletions src/expert/prompts/gobl_code_description.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,69 @@
This tool allows searching the invopop/gobl GitHub repository (main branch) to retrieve relevant code snippets.

The `invopop/gobl` repository is a comprehensive business document processing library that standardizes the creation, validation, calculation, and digital signing of commercial documents such as invoices, payments, deliveries, and orders. Built in Go with WebAssembly support, GOBL provides precise tax calculations, country-specific compliance rules, and multiple distribution channels including CLI tools, HTTP APIs, and browser-compatible modules.

This tool should only be used when a user query is:

- Clearly or implicitly related to the invopop/gobl project.
- Refers to invoicing, invoice formats, validation, payments, lines, totals, tax rules, country-specific rules, or similar GOBL schema fields.

Avoid using this tool if the question is clearly about a different topic, unrelated to the GOBL domain or invoicing in general. For instance, if the question is `How do I configure vscode?` do not use this tool.
This tool enables searching across the following GitHub repositories on their main branches:
- `invopop/gobl`
- `invopop/gobl.verifactu`
- `invopop/gobl.fatturapa`
- `invopop/gobl.cfdi`
- `invopop/gobl.ubl`
- `invopop/gobl.cii`

When used, the tool should:

- Return natural language explanations of the results.
- Include relevant code or documentation excerpts.
- Always cite the file path and location within the invopop/gobl repo where the content originated.

All the sources are in the following URL: https://github.com/invopop/gobl/tree/main. This means that if the source received is addons/de/zugferd/zugferd.go, the URL to the source that you should cite is https://github.com/invopop/gobl/tree/main/addons/de/zugferd/zugferd.go.
All the sources must be in this format: `https://github.com/{repository_name}/tree/main/{file_path}`. This means that if the source received is `addons/de/zugferd/zugferd.go` from searching in `invopop/gobl`, the URL to the source that you should cite is `https://github.com/invopop/gobl/tree/main/addons/de/zugferd/zugferd.go`.

---

## Repository Overview & Selection Criteria

### `invopop/gobl`
This is the **core repository** of the GOBL system and the foundation of the Invopop project.

**Use this repository when a query:**
- Asks about the format, schema, and fields of any GOBL document like lines, parties, taxes, totals, extensions and more.
- Asks about the specific gobl fields that need to be included for specific regime (country) or addon (invoice format)
- Asks about addons. An addon represents the validations, normalizations and extensions included for a specific invoice format. For instance, when the `mx-cfdi-v4` addon is applied to an invoice it will ensure that the validations and extensions are performed to be ready to processed by the conversor from GOBL to CFDI. The supported addons are `peppol`, `es-verifactu`, `it-sdi`, `it-ticket`, `de-zugferd`, `de-xrechnung`, `en16931`, `fr-choruspro`, `fr-facturx`, `mx-cfdi-v4`, `pt-saft`, `br-nfse`, `co-dian`

### `invopop/gobl.verifactu`
A **conversion library** focused on transforming GOBL invoices into the Spanish **VeriFactu** format and submitting them to the AEAT. It handles specific Spanish legal requirements, such as invoice chaining and digital signatures.

**Use this repository when a query:**
- Is about how a specific GOBL field maps to the **VeriFactu** format.
- Involves an error or issue during conversion to VeriFactu.

### `invopop/gobl.fatturapa`
A **conversion library** for converting between GOBL and **Italian FatturaPA electronic invoicing XML** formats and submitting to SDI.

**Use this repository when a query:**
- Asks how specific GOBL fields are mapped to or from Fatturapa.
- Involves conversion errors between GOBL and Fatturapa format.

### `invopop/gobl.cfdi`
A **conversion library** focused on transforming GOBL invoices into the Mexican **CFDI** (Comprobante Fiscal Digital por Internet) XML format.

**Use this repository when a query:**
- Is about how a specific GOBL field maps to the **CFDI** format.
- Involves an error or issue during conversion to CFDI.

### `invopop/gobl.ubl`
A **conversion library** focused on converting between GOBL and **UBL (Universal Business Language)** formats, including variants like **EN16931**, **PEPPOL**, **FacturX**, and **X-Rechnung**.

**Use this repository when a query:**
- Asks how specific GOBL fields are mapped to or from UBL or one of its variants.
- Involves conversion errors between GOBL and UBL formats.

### `invopop/gobl.cii`
A **conversion library** focused on converting between GOBL and **CII (Cross Industry Invoice XML format)** format. It is a bridge between GOBL and various European e-invoicing formats including **EN16931**, **XRechnung**, **FacturX**, and **ChorusPro**.

**Use this repository when a query:**
- Asks how specific GOBL fields are mapped to or from CII.
- Involves conversion errors between GOBL and CII formats.

---

## ⚠️ General Guidance

- **Do not use this tool** for unrelated questions, such as general programming topics (e.g. “How do I configure VSCode?”).
- Query the tool in English
7 changes: 5 additions & 2 deletions src/expert/prompts/gobl_docs_description.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Use this tool to answer questions about GOBL (Invopop's invoice format). The inf
- Details about all the subobjects that compose the previous ones (e.g. lines, parties, taxes, totals ...) and field-level explanations.
- Regime information for every country with the tax categories, rates and invoice type supported
- Information on how to get started with GOBL and how to use the builder to create an invoice
- Addons which provide additional normalization methods, validation rules and extension definitions that augment the basic functionality of a GOBL document with the characteristics of a specific invoice format. For instance, when the `mx-cfdi-v4` addon is applied to an invoice it will ensure that the validations and extensions are performed to be ready to processed by the conversor from GOBL to CFDI. We have one addon per invoice format.
- Addons which provide additional extension definitions that augment the basic functionality of a GOBL document with the characteristics of a specific invoice format. We have one addon per invoice format.
- Addons which provide additional extension definitions that augment the basic functionality of a GOBL document with the characteristics of a specific invoice format. We have one addon per invoice format.
- Catalogues which are sets of extensions that may be used between multiple addons or tax regimes.
- Country-specific extensions and legal compliance details—such as mandatory fields, custom code lists, and localization requirements—for each jurisdiction supported by Invopop.

Expand All @@ -15,4 +16,6 @@ Results return relevant document titles, section headings, and text snippets, en

All the sources are in the following URL: https://docs.gobl.org/. This means that if the source received is draft-0/bill/invoice, the URL to the source that you should cite is https://docs.gobl.org/draft-0/bill/invoice.

Query the tool in English.
Query the tool in English.

The GOBL docs might be incomplete of information, if something is not found here, use the `search_gobl_code` tool in the `invopop/gobl` repo.
Loading
Loading