Bindu icon indicating copy to clipboard operation
Bindu copied to clipboard

[Feature]: DSPY integration

Open raahulrahl opened this issue 11 months ago • 7 comments

DSPy Integration (Simple)

Goal:
Make every Bindu agent improve itself over time — safely.


The idea (one simple flow)

  1. Users give feedback
    Each agent response can be rated (⭐ 1–5 or good / bad).

  2. Feedback is stored
    All interactions and ratings are stored in Postgres.

  3. Create a golden dataset
    A script reads Postgres and selects the best-rated interactions.
    These become the golden dataset.

  4. DSPy improves the prompt
    DSPy reads the golden dataset and generates improved prompt suggestions
    (better instructions, clearer examples, fewer mistakes).

  5. Deploy safely (canary style)
    The new prompt is deployed alongside the old one.
    Traffic is split using a ratio:

    • 90% → old prompt
    • 10% → new prompt
  6. Promote or roll back
    If the new prompt performs better, increase traffic.
    If not, instantly roll back.


What this enables

  • Prompts improve using real user feedback
  • No manual prompt tweaking in production
  • Changes are measurable, reversible, and safe
  • Works with existing Bindu agents and handlers

Mental model

Users rate → data improves → prompts evolve → traffic shifts

Bindu is the feedback loop.
DSPy is the optimizer.
Routing keeps everything safe.


What Bindu owns

  • Interaction + feedback storage (Postgres)
  • Golden dataset generation
  • Prompt versioning
  • Traffic routing (old vs new)
  • Instant rollback

DSPy is simply the optimization engine in the middle.

raahulrahl avatar Dec 12 '25 10:12 raahulrahl

Hey @raahulrahl , I've created a data flow chart to visualize how will the self improving agent will look like. Let me know your thoughts so that I can start implementing it.

  1. USER SENDS MESSAGE POST / → {"method": "message/send", "params": {"message": "Write a poem"}}

  2. TASK CREATED tasks table: {id: "task-1", history: [{role: "user", text: "Write a poem"}]}

  3. WORKER SELECTS PROMPT (Canary Routing) _select_prompt_version() → weighted random → selects v1 (90%) or v2 (10%)

  4. WORKER STORES PROMPT VERSION IN TASK UPDATE tasks SET metadata = {"prompt_version_id": 1} WHERE id = "task-1"

  5. AGENT EXECUTES WITH SELECTED PROMPT message_history = [{"role": "system", "content": prompt_v1}] + user_messages response = manifest.run(message_history)

  6. TASK COMPLETED UPDATE tasks SET state = "completed", history = [..., {role: "agent", text: "Here is your poem..."}]

  7. USER RATES RESPONSE POST / → {"method": "tasks/feedback", "params": {"task_id": "task-1", "rating": 4}}

  8. FEEDBACK STORED WITH PROMPT VERSION INSERT INTO task_feedback (task_id, feedback_data, prompt_version_id) VALUES ("task-1", {"rating": 4, ...}, 1)

  9. ADMIN RUNS OPTIMIZATION (after 50+ ratings) $ bindu optimize-prompts --canary-weight 10

  10. DSPY BUILDS GOLDEN DATASET SELECT tasks.history, feedback.rating FROM tasks JOIN task_feedback ON ... WHERE rating >= 4

  11. DSPY OPTIMIZES PROMPT MIPROv2.compile() → analyzes patterns → generates improved prompt

  12. NEW VERSION CREATED INSERT INTO prompt_versions (version, content, traffic_weight) VALUES ("dspy-20251217", "Improved prompt...", 10.0)

  13. TRAFFIC SPLITS Now: 90% requests use v1, 10% use v2 (the optimized one)

  14. FEEDBACK CONTINUES Users rate v2 responses → stored with prompt_version_id = 2

  15. IF V2 PERFORMS BETTER $ bindu prompts promote v2 → v2 becomes 100%, v1 becomes 0%

  16. IF V2 PERFORMS WORSE $ bindu rollback-prompt -v v1 → instant rollback to v1 at 100%

zaiddkhan avatar Dec 17 '25 07:12 zaiddkhan

hi @zaiddkhan - some contributors are working on it - please join the channel and then @dspy-integrations

raahulrahl avatar Dec 17 '25 08:12 raahulrahl

Hi @raahulrahl

I went through the DSPy integration proposal and the data flow shared above — really like the canary + rollback design.

I understand this is already in progress and coordinated. I’d love to contribute in a scoped way if helpful — for example:

  • DSPy optimization script (golden dataset → prompt),
  • prompt version performance metrics,
  • or a small CLI command / docs around the workflow.

Please let me know what would be most useful and where I should coordinate (channel / thread). Happy to follow existing direction.

Anusha0501 avatar Jan 20 '26 07:01 Anusha0501

Hi @Anusha0501

I’m currently working on this issue. If you’d like to contribute, please message me in the #dspy-integration channel on Discord. I can then assign you a few scoped tasks related to this work.

You’ll find the Discord link in the README.

Avngrstark62 avatar Jan 21 '26 04:01 Avngrstark62

@Avngrstark62 can you please tell me what is the current status now - and what should be the reoadmap?

raahulrahl avatar Feb 11 '26 14:02 raahulrahl

@raahulrahl The basic version of the end to end pipeline is almost ready. Currently we are only supporting the SIMBA optimizer. Also, The canary part is very simple now, we can make it more robust and efficient. I have assigned a contributor to add GEPA optimizer too. Also, we can assign someone to enhance the canary part or we can do this enhancement in the next version.

Avngrstark62 avatar Feb 12 '26 03:02 Avngrstark62

@raahulrahl please review PR #358 when you have time

Avngrstark62 avatar Mar 14 '26 18:03 Avngrstark62