Exploring Programmatic Tool-Calling for AI Agents
2026 (English)Independent thesis Advanced level (degree of Master (Two Years)), 20 credits / 30 HE credits
Student thesisAlternative title
Utforskning av programmatiska verktygsanrop för AI-agenter (Swedish)
Abstract [en]
Large Language Model (LLM)-based agents rely on external tools to extend capabilities for solving complex tasks. However, conventional in-context tool-calling introduces scalability challenges as tool schemas, intermediate outputs, and execution histories accumulate in the model context. This context bloat can increase token usage and latency, elevating the risk of attention dilution and hallucinations in long-horizon workflows. This work investigates Programmatic Tool-Calling (PTC) as an alternative architecture, where the model generates executable code to orchestrate tool calls in an externalised runtime rather than repeatedly calling and passing intermediate tool results through the model’s context window.
To study this, a PTC prototype was implemented on top of an existing LLM system. The prototype supports both traditional in-context tool-calling and PTC, enabling a controlled comparison between the two architectural approaches. The evaluation was conducted using the BFCL and NESTFUL benchmarks, alongside a use-case study conducted in collaboration with an industrial partner company, based on realistic financial tasks. The analysis considers both task efficacy and operational efficiency, including benchmark accuracy, token consumption, latency, tool-call behaviour, and user-perceived quality.
Results reveal a clear performance trade-off across evaluations, with a distinct contrast between task variations. While performance varied slightly depending on the underlying LLM, motivating future research into models explicitly fine-tuned for PTC, general patterns emerged. In single-turn and planning tasks, PTC improved task efficacy with higher success rates, but required an operational trade-off, consuming more tokens in most tasks. This suggests that executable code assists LLMs with logical reasoning and expressing structured tool dependencies more effectively, at the cost of computational resources. Conversely, in long-horizon multi-turn tasks, PTC achieved much higher operational efficiency by mitigating context bloat and drastically reducing total token consumption. However, this efficiency gain came at the expense of task efficacy, indicating that models struggle to maintain stateful understanding over extended trajectories due to the additional abstraction layer introduced by PTC. The use-case study reflected a middle-ground, where PTC reduced overall input token usage and irrelevant tool calls while maintaining similar success ratings, but these efficiency gains did not consistently correlate with higher user satisfaction.
Ultimately, the findings indicate that PTC is a promising but context-dependent alternative to standard in-context tool-calling. While it can improve efficiency and structured tool use in some settings, its benefits are not consistent across all models and tasks. Therefore, the adoption of PTC should be strategically tailored to specific use cases, favouring complex, data-dense single-turn tasks over extended conversational workflows.
Place, publisher, year, edition, pages
2026. , p. 77
Keywords [en]
Large Language Models (LLMs), Natural Language Processing (NLP), AI Agents, Agentic Systems, Programmatic Tool-Calling (PTC), Tool Calling, Function Calling, Benchmarking, User Tests, Automated Evaluation Metrics
National Category
Natural Language Processing Artificial Intelligence
Identifiers
URN: urn:nbn:se:liu:diva-225750ISRN: LIU-IDA/LITH-EX-A--26/043--SEOAI: oai:DiVA.org:liu-225750DiVA, id: diva2:2080143
External cooperation
Modular Finance
Subject / course
Computer Engineering
Presentation
2026-06-03, Linköping, 13:15 (English)
Supervisors
Examiners
2026-07-242026-06-262026-07-24Bibliographically approved