Building a Robot Agent Framework with Open-Source LLMs: Design and Implementation Considerations

    This article examines the practical challenges of building robot agent frameworks using open-source large language models (LLMs) instead of closed-source APIs. It outlines three key limitations of closed-source models in robotic tasks, presents four core requirements for a unified framework design, details a clean interface approach that decouples cognitive planning from low-level control, and provides guidance on reporting reproducible experimental results. The included Python code sample demonstrates a complete scheduling loop with tool validation, retry logic, and experience recording for downstream fine-tuning.

    Three Limitations of Closed-Source Models in Robotic Tasks

    Many robot agents rely on closed-source frontier models accessed via API calls. However, sustained development with this approach presents three recurring problems.

    Obstacle Practical Impact How Open-Source Approaches Address It
    Weights are unavailable Real-robot interaction data cannot be used for fine-tuning; model capability remains at factory defaults Use open weights, convert runtime logs into training corpora, and fine-tune periodically
    API costs scale with usage Cost estimation for large-scale simulation and real-robot testing becomes unpredictable Deploy models locally, pay for compute, and track per-task cost
    Inference cannot be intervened Hard to optimize for specific manipulator dynamics; deployment efficiency on resource-constrained devices is low Apply model quantization and inference engine optimization; scale model size to target hardware

    Four Requirements for a Unified Framework

    A unified framework serves two purposes: enabling zero-shot manipulation tasks with open-source models, and converting runtime traces into reusable training data. At minimum, it must satisfy the following requirements.

    1. Decoupled cognition and control. The LLM handles instruction understanding, task decomposition, and tool selection. Low-level control is executed by the robot’s built-in controllers. The framework sits between the two, translating natural-language goals into tool invocations.

    2. Explicit tool schemas. Every tool must declare its name, parameter names, parameter types, and value ranges. When the model’s output deviates from a tool’s schema, the framework rejects the execution and returns the error message to the model.

    3. Fixed state representation. Observations at every step use the same structure, such as a list of objects, end-effector position, gripper status, and the result of the previous step. A fixed structure ensures that logs can be directly used for training.

    4. Unified data format with pluggable models. Each step records a four-tuple—previous state, action, execution result, and new state—along with a task ID, timestamp, and model version. All open-source models connect through the same planning interface, so swapping models does not require changes to the tool layer.

    Interface Design: Orchestrate Controllers Instead of Outputting Joint Commands

    When a model directly outputs joint torques or joint angles, task success rates tend to be low. A more effective approach is to have the model invoke pre-trained controllers or a set of atomic tools, such as locate, move-to-coordinate, grasp, and release. This layered design only covers actions that the tools can perform. If the model requests an action that no tool covers, the framework should report failure rather than let the model assemble low-level commands on its own.

    The following code sketch shows the scheduling loop. Compared to conventional implementations, it introduces three changes: observations are refreshed after every step; parameters are validated before each action executes; failure messages are fed back into the next planning round; and complete state transitions are recorded.

    1. class RobotAgentHarness:
    2. def __init__(self, llm_model, robot_interface, max_steps=20, max_retries=2):
    3. self.llm = llm_model
    4. self.robot = robot_interface
    5. self.max_steps = max_steps
    6. self.max_retries = max_retries
    7. self.tools = {
    8. "locate_object": {"fn": self.robot.locate_object, "params": {"name": str}},
    9. "move_to_coord": {"fn": self.robot.move_to_coord,
    10. "params": {"x": float, "y": float, "z": float}},
    11. "grasp_object": {"fn": self.robot.grasp_object, "params": {"object_id": str}},
    12. "release_object": {"fn": self.robot.release_object, "params": {}},
    13. }
    14. def tool_schemas(self):
    15. return {name: spec["params"] for name, spec in self.tools.items()}
    16. def validate(self, tool_name, params):
    17. if tool_name not in self.tools:
    18. raise ValueError(f"Unknown tool: {tool_name}")
    19. schema = self.tools[tool_name]["params"]
    20. if set(params) != set(schema):
    21. raise ValueError(f"Parameter mismatch for {tool_name}: {sorted(params)}")
    22. for key, typ in schema.items():
    23. if not isinstance(params[key], typ):
    24. raise TypeError(f"{tool_name}.{key} should be {typ.__name__}")
    25. def call_with_retry(self, tool_name, params):
    26. last_error = None
    27. for _ in range(self.max_retries + 1):
    28. try:
    29. return {"ok": True, "value": self.tools[tool_name]["fn"](**params)}
    30. except TimeoutError as e:
    31. last_error = e
    32. return {"ok": False, "error": str(last_error)}
    33. def execute_task(self, task_description):
    34. obs = self.robot.get_state()
    35. last_result = None
    36. for _ in range(self.max_steps):
    37. plan = self.llm.plan_next(task_description, obs,
    38. self.tool_schemas(), last_result)
    39. if plan["done"]:
    40. break
    41. action = plan["action"]
    42. try:
    43. self.validate(action["tool"], action["params"])
    44. result = self.call_with_retry(action["tool"], action["params"])
    45. except (ValueError, TypeError) as e:
    46. result = {"ok": False, "error": str(e)}
    47. next_obs = self.robot.get_state()
    48. self.record_experience(obs, action, result, next_obs)
    49. obs, last_result = next_obs, result
    50. return obs

    The record_experience method writes each four-tuple as a JSON line to a local file or object storage for later fine-tuning. call_with_retry retries only on timeout; other errors are returned to the model, which then decides on an alternative approach. For production use, each tool should have an execution timeout, and the real robot should be connected to an emergency stop signal.

    Experiments and Performance: How to Write Reproducible Results

    Performance numbers are only meaningful when accompanied by experimental conditions. A reproducible report should include at least the following:

    • Benchmark name, version, number of tasks, and how the split was performed.
    • Success criteria, such as the position error tolerance in centimeters.
    • Model name, parameter count, weight version, and inference precision.
    • Hardware environment, including GPU model, robot model, and control frequency.
    • Number of repetitions per task, plus the mean and variance of success rates.
    • Cost metrics, including per-task inference time, GPU hours, or API cost, with the unit price source indicated.
    • Differences between the control and experimental groups, including whether prompts, tool sets, and retry counts are consistent.

    Zero-shot means the evaluation uses no demonstration data and no task-specific fine-tuning. Ground-truth information from the simulation environment, such as exact object positions, must not be provided as model input.

    When this information is not available, only qualitative conclusions can be reported, for example, that an open-source model performed well or poorly on the tested tasks under the specified conditions.