Skip to content

Improve buyer booking flow and integrate Meta and GAM Reporting#87

Open
Sirajmx wants to merge 9 commits into
mainfrom
feature/meta-integration
Open

Improve buyer booking flow and integrate Meta and GAM Reporting#87
Sirajmx wants to merge 9 commits into
mainfrom
feature/meta-integration

Conversation

@Sirajmx
Copy link
Copy Markdown
Contributor

@Sirajmx Sirajmx commented May 19, 2026


Meta Ads Integration, Booking Workflow Fixes & Reporting Architecture


Meta Ads Integration (commits 68b96cf, db60b68)

deal_booking_flow.py — Social channel bookings go through the Meta Graph API (graph.facebook.com) directly via
_book_via_meta_api(): creates campaign → ad set per recommendation. Campaigns are created in paused state awaiting
creative review. MetaAdsClient wraps the Graph API calls.

settings.py — META_ACCESS_TOKEN, META_AD_ACCOUNT_ID, META_PAGE_ID, META_API_VERSION added.

docs/integration/meta-ads.md — Public MkDocs page covering setup, Graph API booking flow (sequence diagram), reach
estimate configuration, and reporting.


Buyer Booking Workflow Fix (commit 88e9965)

Resolved booking flow failures when calling the seller agent.

deal_booking_flow.py — Rewired the full quote → deal → order sequence against the seller's IAB Deals API v1.0
endpoints (/api/v1/quotes, /api/v1/deals, /api/v1/orders). Added _book_via_meta_api() and _book_via_seller_api() as
separate booking paths per channel type.

opendirect_client.py — Migrated from a persistent self._client to per-request _make_client() pattern, fixing "Event
loop is closed" errors when CrewAI crews run kickoff() in worker threads with their own event loops.

channel_crews.py, portfolio_crew.py — Channel research crews now call the seller's product search and avails
endpoints correctly. Budget allocation prompt updated to enforce the channels field from the campaign brief,
preventing the LLM from allocating to channels not requested.


Budget Allocation Fix (commit 1da09b7)

portfolio_crew.py — LLM prompt now injects a hard constraint when channels is specified in the brief ("MUST allocate
across ONLY these channels"). deal_booking_flow.py adds an Option B proportional rescale fallback in case the LLM
still returns wrong channels.


Reporting Architecture: GAM moved to seller (commits 43b1dfe, ba7d433, b86083d)

GAM is a sell-side ad server — buyers don't have GAM accounts. The architectural correction:

  • Removed GAMReportingClient, GAMReportingTool, GET /gam/orders, GET /gam/report from buyer agent entirely
  • Removed GAM settings (GAM_ENABLED, GAM_NETWORK_CODE, GAM_JSON_KEY_PATH etc.) from settings.py and .env
  • Added seller_deal_id: str | None to BookedLine — stored at booking time so the reports endpoint can look up
    delivery without a separate API call
  • GET /reports/{job_id} now routes non-social lines to the seller agent's GET /api/v1/deals/{deal_id}/performance
    endpoint (the correct A2A path), keeping Meta Graph API for social lines
  • docs/integration/gam-reporting.md removed from buyer; meta-ads.md cross-reference updated

Lint, Formatting & Test Fixes (commit 7801146)

opendirect_client.py — Completed _make_client() migration for all remaining account/order/line/creative methods (14
methods still used self._client after the partial May 2 migration).

Test fixes: test_client.py, test_deal_booking_flow.py, test_error_propagation.py — replaced
patch.object(client._client, ...) with proper async context manager mock via patch.object(client, "_make_client",
...). TestApprovalAndBooking patched _book_via_seller_api to mock the HTTP call; corrected booking_status assertion
from "pending_execution" → "booked".

Ruff E501, F401, N806 violations fixed across modified files.

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