https://www.boundaryml.com logo
🟡 Understanding the Ecosystem around LLMs and bam...
# questions
r
baml is amazing 🙂 but what is probably even more amazing is the whole philosophy around interacting with LLMs / agents, the inversion of control, the taxonomy around low / med /high stakes tasks, etc. So many awesome ideas! A bit hard for a newcomer to this ecosystem to wrap my head around how all the pieces fit together. Could I please ask you if you would be so kind and confirm my understanding? 1. humanlayer gives you functionality for human-in-the-loop that bolts onto other sdks, like openai agents / vercel ai sdk? 2. baml supports function calling from Python, but the function needs to be defined in typescript? meaning, there is no sane way to call functions I define in Python using baml? 3. Is there any way to access codelayer atm? I tried to search around but it doesn't seem to be available to the public? 4. If indeed I cannot call python functions using baml, what other sdk would you recommend? Ideally one that can best integrate with boundaryml tooling? Thank you so much for all your help, what an amazing ecosystem of tools you are building! 🙏
a
BAML compiles clients for many languages including python https://docs.boundaryml.com/guide/installation-language/python
r
ty @anerli! yes, I get that part -- I can make requests to LLM api endpoints using baml from Python (call my baml defined functions), but for tool calls, I cannot define tools in Python. I can only use functions defined in typescript as tools, right? For instance, if I would like to implement an agent that operates on numpy arrays, this is something that currently would not be possible using baml, right?
a
oh gotcha, yeah usually what you wanna do is in your baml function generate a response that can be fed into whatever tool you want, then feed the output of that function back into context in whichever way makes the most sense for your agent
its not as "automatic" as the typical tool calling apis but the control allows for far better results when used intentionally
r
oh wow if I could do this that would be great! I can look after the tool calling myself, there are other libraraies that implement a lot of the plubming for that, where I could generate the schema automatically from a python function etc
a
yeah it is possible with typebuilder to construct schemas dynamically, and you could use pydantic schemas or introspect python type hints to create those schemas if you wanted to have a more python-native experience
r
thank you so much for this, @anerli, super helpful! 🙂 🙏 I now just need to figure out what the pattern for tool calling is with baml....
As in, how do we communicate to the model the tools it can call and how do we get the response... is it via the regular ToolCall field that the api returns or some other approach
a
You don't use a formal or separate concept of "tool calling" in baml - you generate JSON and interpret it as the parameters to a tool that you define yourself, which is a lot more powerful in practice
r
So if I am reading this right, it seems we can give the model the option to return a "tool call" or some other response via this:
Copy code
function UseTool(user_message: string) -> WeatherAPI | MyOtherAPI {
  .... // same thing
}
a
yeah like WeatherAPI is just a json response format
but in your own code you are implementing what to actually do with that response, how to call the appropraite function, and what to do next based on that
r
wow, that is very cool, very eye-opening, I wouldn't be able to figure this out just by reading the docs (it seems I completely misunderstood what was happening there the first time I read them)
but fundamentally, why does that work? models are trained for function calling, this is trained into their outputs that get parsed by the prompt format template (harmony for openai, etc)
very cool that the baml way of handling structured output and tool calling works so well, just quite surprising if one maps it to how structured output / tool calling is implemented essentially everywhere else
a
i think fundamentally its just a simpler format for llms to follow regardless of other format-specific training. even if a model is trained to produce output following ugly json-schema specifications, if it's presented with the simpler baml response instructions it will still follow it better
an exception might be XML-based response formats like anthropic did when training models for claude code tool calling, which is very effective
r
it could be the case... but these models should probably follow the format they are trained on really, really well, with the current gen of models it is probably quite hard to get them to deviate from the format
one other thing that might be happening is that the model doesn't really know how it is getting called, which path we take in the openai sdk, to the model it is all the same -- it just outputs text, but instead of the sdk parsing it for us into tool calls / structured output, baml just handles all that in a more intelligent way, but relying on the formatting trained into the model
I gotta run now, but you saved my life, @anerli, thank you so much! 😄
I thought I would have to use openai's agent sdk, but there appears to be a baml-native way to achieve exactly what I want
thank you so much 🙏
a
yes baml all the way, hope you find it as useful as I have!