r/PiCodingAgent • • 1d 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

68 Upvotes

17 comments sorted by

8

u/invin10001 1d 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 1d 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.

2

u/ThankYouOle 22h ago edited 21h 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.

0

u/invin10001 1d ago

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

1

u/Tafes-Haiba13 1d 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 20h ago

Why did you choose Langgraph?

1

u/behopkinsj 19h 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 8h 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 8h 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 7h 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 1d 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 1d 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 1d 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 1d 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 1d ago

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

4

u/swagonflyyyy 1d ago

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

Guess it worked lmao.

-2

u/No-Sandwich1809 1d ago

Low key would you built this, props. Saving real money is a flex too. Most devs just chase cool features, but cost-cutting? That’s the real upgrade. Gonna give it a spin soon!