r/PiCodingAgent • • 2d ago

Plugin I Built an Orchestration Plugin That's Been Saving Me Costs

Post image

I built an orchestration plugin for Pi, with the goal of optimizing costs and making Pi more precise.

I've been wanting to build this for a while; it uses LangGraph to link agents together so that they focus on a single task, while Pi acts as the orchestrator. Once an orchestration flow is created, it can be reused later. So once you have an automation that works well, you can use it however many times you'd like.

So far, it's been saving me cost with long-running tasks. What do you all think?

Website: https://leafi.app/pi/
GitHub: https://github.com/Bruce-Hopkins/Leafi

77 Upvotes

18 comments sorted by

10

u/invin10001 2d ago

Wait, how does putting multiple agents on the same task save costs? Shouldn't you break down the task so each is byte-sized for the right agent to pick up and implement? Maybe I'm missing the bigger picture, can you elaborate with an example?

5

u/behopkinsj 2d ago

Yeah! So the agents pass context to each other. One works, and only sends the information to the next agent. So each agent isn't receiving the full conversation, just the work it needs.It ends up saving on cost.

Since a single LLM isn't reading the entire history, the agents tend to be more accurate too.

4

u/ThankYouOle 2d ago edited 2d ago

i am working on my own solution with this similar approach, but my log said it didn't work like that.

imagine like this:

- agent 1 read the file for mapping and planning

- it create good list file and plan, and then return it to the 'manager',

- then manager bring that output as context for 2nd agent,

- in my expectation the 2nd agent already have knowledge and context, but turn the 2nd agent kind of didn't trust it,or ignore it, and keep re-reading all the files and history.

but i notice this kind of behavior only on Deepseek model, i tried with Terra it goes straight away even without mapping.

1

u/learning-to-programm 3h ago

I notice agents doing that, but I very much encourage it. I mean l, of course, reviewing plans and re-read ING files has to end at some point, but I much prefer that each does the due diligence regarding their task, rather than blindly trust whatever whoever came before them gave them.

1

u/ThankYouOle 2h ago

Its about balance and preference really.

In some case it help on clarity but in some case it add processing time because it re-read again, which mean extra cost and extra token allocation.

0

u/invin10001 2d ago

I see it now. Neat. I'll try it out.

1

u/Tafes-Haiba13 2d ago

suspect they just worded that part weirdly and meant each agent gets its own narrow sub-task, so youre not stuffing the entire repo into one giant context window on every turn

1

u/patrick9331 1d ago

Why did you choose Langgraph?

1

u/behopkinsj 1d ago

I wanted to use something that could be used by whichever agents, if you choose to. But it's in it's earlier phases, so I might change the frameworks if that makes the plugin better

1

u/R3VO360 1d ago

Noob here, what's the difference between this and plain langgraph? Can you design a workflow where each node can decide whether it is needed to re-run the previous step of the pipeline with different parameters?

2

u/behopkinsj 1d ago

The main difference is that this gives you a lot of control. So you can set token budgets for each agent, Pi can link the agents by just tool calls instead of writing code, Pi can set the permissions of each node and let you know the final cost afterwards.

It basically gives Pi the freedom to make whatever graph it wants without having to write the code from scratch, so Pi can make quick design choices and iterate based on its learn feedback much quicker.

1

u/R3VO360 1d ago

I see! So basically, with langgraph you design the graph, while with leafi, Pi designs it based on what you need. Thanks for the clarification!

1

u/fingerthief 2d ago

Are there any numbers or measurements on cost?

All the studies and papers I’ve read on orchestration along with my own evals show it’s basically never actually cheaper. Certainly useful for other reason but not for cost.

0

u/behopkinsj 2d ago

I tried on Goose and it seemed to cut the cost in certain runs by 70%. I was mainly testing with web scapping. It mainly excels at multistep instructions, since they can be broken down with different agents and models. With DeepSeek, what one agent scrapped with 0.14$ to 0.50$, with the tool it ran at 0.04$ to 0.14$.

It also depends on the circumstances. Testing with LLMs are not deterministic. I'll have to find ways to do bigger and better tests.

0

u/fingerthief 2d ago

I could see potentially for scraping it could be cheaper. I think for real code implementation and research it likely would end up costing more.

I’d recommend running some available evals like SWE-bench or something similar and comparing the results.

I’d be super interested in seeing the result! There are many ways to do orchestration, always cool to see variations.

0

u/behopkinsj 2d ago

I'll have to do more testing on code. My thinking is that for research, or testing it might be more efficient. But we'll see.

Thanks! I'm glad you find it interesting

0

u/adamshand 2d ago

Yeah same. Everything I've read and tried seems better & cheaper to just use a single agent for most situations.

4

u/swagonflyyyy 2d ago

I was using a different one and noticed my orchestrator agent ranting:

Guess it worked lmao.