Tool Dispatch: A Dictionary Replaces a Switch Statement and Scales to 14 Tools
Our agent can do a lot with just bash. It can read files with cat, write them with echo, search with grep, compile with swift build — a shell command is a universal interface to the operating syste...

Source: DEV Community
Our agent can do a lot with just bash. It can read files with cat, write them with echo, search with grep, compile with swift build — a shell command is a universal interface to the operating system. So why would we need anything else? The answer becomes clear when we watch the agent work. It reaches for cat to read a file, and the output silently truncates at some terminal buffer limit. It constructs a multi-line sed command to edit a source file, and one misplaced backslash corrupts the content. Every file operation goes through a shell command that the model has to construct from scratch, with no guardrails and no safety boundaries. Dedicated tools like read_file and write_file let us enforce constraints — path sandboxing, output limits, atomic writes — at the tool level rather than hoping the model's bash commands happen to be correct. In this guide, let's build a tool dispatch system that scales to any number of tools without changing the agent loop. We'll add three new tools — re