Skip to main content

Agent Implementation

The finance research agent was implemented using LangGraph with the following multi-agent architecture. Try for yourself. Financial Research Agent

Contract Specification

We can now define the scenarios and corresponding contract in a Specification.
define.py
Check out the outputed json file: specification.json.

Running the Agent

Start the verification server from the agent-contracts directory (make sure you’ve downloaded and installed agent-contracts repo installation). The verification server includes the telemetry collector necessary to receive the traces from the agent instrumented with relari-otel.
Now run the app (the default command will run the scenarios defined in specification.json). Make sure you’ve installed the langgraph-fin-agent README.
You can now viwe the traces in the Jaeger UI at http://localhost:16686. Or you can fetch the traces via the Agent Contracts CLI.
$ poetry run cli ls run —timespan 1h
Listing runs from 2025-03-11 04:27:05.937162+00:00 to 2025-03-11 05:27:05.937158+00:00…
┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ Run ID   ┃ Project Name        ┃ Specifications ID ┃ Start Time          ┃ End Time            ┃
┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ 187a8d09 │ langgraph-fin-agent │ yw936jmp          │ 2025-03-10 21:56:20 │ 2025-03-10 21:56:20 │
└──────────┴─────────────────────┴───────────────────┴─────────────────────┴─────────────────────┘

Verification Results

The following is the verification results post-execution. We can see that the con-comparison and con-analysis contracts are satisfied while the con-liquidity-analysis contract is not.
$ poetry run cli verify run 187a8d09 /Users/yisz/code/Relari/agent-examples/apps/langgraph-fin-agent/specifications.json —timespan 1d
Verifying run 187a8d09 with specifications from agent-examples/apps/langgraph-fin-agent/specifications.json…
Output will be saved to output/verify_187a8d09.json
Contract Right Tickers: 100%|████████████████████████████████████████████████████████████| 3/3 [00:06 < 00:00,  2.06s/it]
Contract Right Tickers: 100%|████████████████████████████████████████████████████████████| 4/4 [00:08 < 00:00,  2.22s/it]
Contract Right Tickers: 100%|████████████████████████████████████████████████████████████| 4/4 [00:10 < 00:00,  2.64s/it]
─────────────────────────────────────── Trace 6f644c2e191daa723fcd7effac3de3e0 ────────────────────────────────────────
Right Tickers (UNSATISFIED)
┏━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓ ┃ Type ┃ Qualifier ┃ Requirement ┃ Satisfied ┃ ┡━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩ │ PRE │ MUST │ Question about the debt-to-equity ratio │ Yes │ │ PATH │ MUST │ Retrieve the financials of at least 3 car manufacturers │ No │ │ POST │ MUST │ Output a table │ No │ │ POST │ SHOULD │ Include at least Tesla, Ford, and General Motors │ No │ └──────┴───────────┴─────────────────────────────────────────────────────────┴───────────┘ ─────────────────────────────────────── Trace 0cbce717cb265f18e45f6047c3f6060d ──────────────────────────────────────── Right Tickers (SATISFIED)
┏━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓ ┃ Type ┃ Qualifier ┃ Requirement ┃ Satisfied ┃ ┡━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩ │ PRE │ MUST │ Comparison between Nike and Adidas │ Yes │ │ PATH │ MUST │ Retrieve Nike financials with the ticker NKE │ Yes │ │ PATH │ MUST │ Retrieve Adidas financials with the ticker ADDYY │ Yes │ │ POST │ SHOULD │ A numeric value for operating margins expressed in percentage │ Yes │ └──────┴───────────┴───────────────────────────────────────────────────────────────┴───────────┘ ─────────────────────────────────────── Trace 7d01b56e279cc75e44a3b2e57890b9bd ──────────────────────────────────────── Right Tickers (SATISFIED)
┏━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓ ┃ Type ┃ Qualifier ┃ Requirement ┃ Satisfied ┃ ┡━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩ │ PRE │ MUST │ Question about Tesla’s net income │ Yes │ │ PATH │ MUST │ Retrieve Tesla’s net income with the ticker TSLA │ Yes │ │ POST │ SHOULD │ A numeric value for net income expressed in dollars │ No │ └──────┴───────────┴─────────────────────────────────────────────────────┴───────────┘
You can further inspect the detailed verification results with reasoning in the output/verify_187a8d09.json file.