0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【物流AI #18】LLM×ロボット:自然言語でタスク計画を生成する

0
Posted at

【物流AI #18】LLM×ロボット:自然言語でタスク計画を生成する

なぜ LLM をロボット制御に使うか

「棚 A3 の赤いボックスをコンベア B に運んで」という自然言語をロボットが理解できれば、専用 GUI が不要になる。LLM にタスク計画を生成させ、低レベル制御は従来の RL モデルに任せるハイブリッドアプローチが現在のベストプラクティスだ。

LLM によるタスク分解

import openai, json

SYSTEM_PROMPT = """あなたは倉庫ロボット制御エージェントです。
以下のアクション定義に従い、タスクをステップに分解してください。
利用可能なアクション:
- move_to(location: str)
- pick(item: str)
- place(location: str)
- check_inventory(location: str)
JSON 配列で返してください。"""

def plan_task(instruction: str) -> list[dict]:
    resp = openai.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user",   "content": instruction}
        ],
        response_format={"type": "json_object"}
    )
    return json.loads(resp.choices[0].message.content)["steps"]

plan = plan_task("棚 A3 の赤いボックスをコンベア B に移動して")
# [{"action":"move_to","args":{"location":"A3"}},
#  {"action":"pick","args":{"item":"red_box"}},
#  {"action":"move_to","args":{"location":"conveyor_B"}},
#  {"action":"place","args":{"location":"conveyor_B"}}]

計画実行エンジン

class PlanExecutor:
    def __init__(self, rl_policy, safety_monitor):
        self.policy  = rl_policy
        self.safety  = safety_monitor
        self.actions = {
            "move_to":        self._move,
            "pick":           self._pick,
            "place":          self._place,
            "check_inventory": self._check_inv,
        }

    def execute(self, steps: list) -> bool:
        for step in steps:
            fn = self.actions.get(step["action"])
            if fn is None:
                print(f"未知のアクション: {step['action']}")
                return False
            ok = fn(**step["args"])
            if not ok:
                print(f"失敗: {step}")
                return False
        return True

    def _move(self, location: str) -> bool:
        obs = get_obs(self.current_pos, location)
        for _ in range(200):
            act = self.policy.act(obs)
            obs, _, done, info = env.step(act)
            if info.get("arrived"): return True
        return False

エラー回復:LLM に再計画を依頼

def replan(original_plan, failed_step, error_info):
    prompt = f"""以下の計画の {failed_step} 番目のステップが失敗しました。
エラー: {error_info}
元の計画: {json.dumps(original_plan, ensure_ascii=False)}
修正した計画を JSON で返してください。"""
    return plan_task(prompt)

アーキテクチャまとめ

自然言語指示
    ↓ LLM(タスク分解)
ハイレベル計画 [move, pick, place, ...]
    ↓ PlanExecutor
RL低レベル制御 → SafetyMonitor → ロボット
    ↑ 失敗時
    LLM 再計画

シリーズ: 物流・倉庫 AI 実装ガイド 2026 (18/20)

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?