CoolFace
Apppublic

gparab1987/CoverageComplianceAgent

sourceHugging Facemitupdated 17d agoView on Hugging Face
0likes
App README

Coverage Compliance Agent

A LangGraph agent that verifies whether a rental customer's auto insurance policy meets a rental company's coverage requirements — and keeps watching for changes mid-rental. Built against a mock Axle client whose method signatures and response shapes mirror the real Axle API exactly, so it's ready to point at the real sandbox once you have credentials.

What it does

fetch_policy -> validate_coverage -> compliance_report
                                            |
                                  (1st pass) -> monitor_change
                                            |
                                  refresh_policy_after_event
                                            |
                                   validate_coverage (loop)
                                            |
                                    compliance_report
                                            |
                                  (2nd pass) -> END
  1. 1.fetch_policy — mimics Ignition consent -> token exchange -> GET /policies/{id}
  2. 2.validate_coverage — checks the policy against configurable rules (active status, minimum liability, comprehensive/collision required) and generates a plain-language explanation of the verdict
  3. 3.compliance_report — produces a verdict + recommended next action
  4. 4.monitor_change — simulates an Axle policy.modified webhook firing mid-rental (e.g. the policy gets cancelled)
  5. 5.Loop: the policy is refreshed and re-validated, and a second report is generated reflecting the change

Files

FilePurpose
axle_client.pyMockAxleClient — mirrors Axle's start_ignition, exchange_token, get_policy, and a sandbox event simulator. Includes 4 fixture policies (compliant, underinsured, expired, cancelled-mid-session).
state.pyLangGraph state schema (TypedDict)
nodes.pyNode functions, plus a pluggable LLM explainer (falls back to a deterministic template if OPENAI_API_KEY isn't set)
graph.pyWires the nodes into the StateGraph above
main.pyDemo runner — executes all 4 fixture scenarios
app.pyGradio frontend — pick a policy, set coverage rules, run the agent, and see the initial verdict vs. post-event re-validation side by side. Deployable as-is to a Hugging Face Space (SDK: gradio).

Running it

bash
pip install -r requirements.txt
python main.py       # CLI demo, runs all 4 scenarios
python app.py         # Gradio UI at http://127.0.0.1:7860

Optional — for LLM-generated explanations instead of the deterministic template, set an API key and install the OpenAI integration:

bash
pip install langchain-openai
export OPENAI_API_KEY=sk-...
python main.py

Going from mock to live Axle sandbox

Everything in nodes.py and graph.py talks to Axle only through the axle_client object. To go live:

  1. 1.Get sandbox credentials from Axle (x-client-id / x-client-secret)
  2. 2.Replace MockAxleClient in nodes.py with a real client, e.g.:
python
class LiveAxleClient:
    def __init__(self, client_id: str, client_secret: str):
        self.headers = {"x-client-id": client_id, "x-client-secret": client_secret}

    def start_ignition(self, user_id: str) -> dict:
        r = requests.post(
            "https://api.axle.insure/ignition",
            headers=self.headers,
            json={"user": {"id": user_id}},
        )
        return r.json()

    # ... exchange_token, get_policy, trigger_policy_event follow the same
    # pattern, hitting api.axle.insure / sandbox.axle.insure instead of
    # returning fixture data.
  1. 1.Swap the module-level axle_client = MockAxleClient() line in nodes.py for axle_client = LiveAxleClient(client_id, client_secret)

No other file needs to change — the node functions, the graph, and the demo script are all written against the same interface either way.

Notes / known simplifications

  • monitor_change is called inline in the graph for demo purposes. In a real deployment this would instead be a webhook handler that re-enters the graph when Axle POSTs a policy.modified event — not something the graph triggers itself.
  • The demo always simulates a "cancelled" event for illustration; in practice you'd branch on the real event type Axle sends.
  • MockAxleClient is a stateful singleton shared across scenario runs in main.py, so each scenario resets its policy back to the original fixture state before running.