Find answers from the community

Updated 2 weeks ago

Function calling

Hi, is there an easy to do function calling in workflows?

I followed the complete tutorial for workflows but I didn't find a function calling example.

This is the guide I followed. https://docs.llamaindex.ai/en/stable/module_guides/workflow/#workflows

I did find an example of function calling in Jupyter Notebooks but it contained a lot of low level/boilerplate code I really don't want to write everytime I want to do function calling in my workflows.

This is what I am referring to:
https://docs.llamaindex.ai/en/stable/examples/workflow/function_calling_agent/
L
h
3 comments
It's based on the api demonstrated here
https://docs.llamaindex.ai/en/stable/examples/llm/openai/#manual-tool-calling

It's fairly straightforward. chat_with_tools -> get_tool_calls_from_response -> call those tools

I actually made a video on this
https://youtu.be/wuuO04j4jPc?si=4ObWLWICPdRB90yh

Video materials
https://github.com/run-llama/multi-agent-concierge/tree/main/video_tutorial_materials


If your just interested in structured outputs, there are simpler (but less customizable) approaches. This is a great guide
https://docs.llamaindex.ai/en/stable/understanding/extraction/
This still contain a lot of boilerplate code, for instance, I want to automatically run function calls when any agent suggests it without me having to explicitly move function arguments around like agents

https://docs.llamaindex.ai/en/stable/module_guides/deploying/agents/usage_pattern/
If you want to automatically run function calls, use a prebuilt agent

Plain Text
from llama_index.core.agent import FunctionCallingAgent

agent = FunctionCallingAgent.from_tools(tools, llm=llm)
agent.chat("Hello!")


This will automatically do an entire agent loop (tool calling, writing a final response, etc.)

The advantage of the "boilerplate" code I was linking above is you can get more control over how things are called (which tbh, is extremely helpful, better error handling, ensuring certain things happen when a tool is called, injecting arguments, etc.)
Add a reply
Sign up and join the conversation on Discord