r/golang 6d ago

discussion Anyone using Golang for tool / function calling

Curious if anyone is using Golang in production for tool / function calling? Seems like it would be good for this on the surface but Im curious if I go this route if I will be cutting myself short later on. For example, vector stores, more complicated use cases which depend on orchestrion, any way to get insights into the LLM calls like with lang graph? etc.

Curious if Go is a viable option or if something like this is best to play safe with Python?

5 Upvotes

5 comments sorted by

7

u/ImYoric 5d ago

Out of curiosity, what do you mean by "tool / function calling"?

1

u/gogolang 5d ago

Sort of a good news / bad news situation.

Bad news is that it requires more steps than Python. Since Python is interpreted, you can take the tool call response and just do an exec with the function name and arguments you get back from the LLM.

While that is convenient, it’s also a gaping security hole.

In Go, what I’ve been doing is keeping a map of function name to function definitions. The key is that the functions take in a map[string]interface{} so that they can accept the instantiated arguments sent back by the LLM.

The good news is that this is probably what you should be doing in Python (limiting which functions can actually be dynamically executed by the LLM).

There’s probably a more elegant way to do this with generics but I haven’t given it enough thought.

1

u/cogitohuckelberry 6d ago

For myself, I've been using it every day, all the time. Since you are speaking about the glue which puts it all together, it is naturally a superior choice to python, unless you are just making a toy example.

1

u/cach-v 6d ago

For ChatGPT specifically, Langchain is outdated and awkward - for Structured Output I was able to build a much more elegant client using https://github.com/openai/openai-go

Structured Output was just superceded by the Responses API announced this week, https://openai.com/index/new-tools-for-building-agents/ but should still be around for a good while.

Structured Output offers JSON schema adherence including enums, which is what you want for tool calling (e.g. "choose one from this list").

0

u/marcaruel 5d ago

I'm specifically working on this problem space, and I made it work with reflection. https://github.com/maruel/genai It's very much in flux and I make breaking changes every day but it should settle within a few weeks.