1
0

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自動売買システムを並列化&ログ可視化を強化しました(マルチエージェントの進化)

Last updated at Posted at 2025-12-06

はじめに

個人開発しているAI自動売買システム「Stock Predictor」のアーキテクチャを改良しました。
これまでは「日本株」「米国株」「仮想通貨」の3つのエージェントが直列(順番)に動いていましたが、これを完全並列化し、さらにログ表示を3画面分割にしてリアルタイム性を高めました。

改善ポイント1: エージェントの並列実行 (Multi-threading)

これまでは for ループで各エージェントを順番に処理していたため、例えば「米国株エージェント」がAPI通信で待たされると、「仮想通貨エージェント」の判断も遅れるという課題がありました。

今回、Pythonの threading モジュールを使用して、各エージェントを独立したスレッドで動作させるように変更しました。

# services/auto_trading_agent.py (抜粋)

def start(self):
    # 各エージェントごとにスレッドを起動
    for config in self.agents_config:
        name = config['name']
        thread = threading.Thread(target=self._run_agent_loop, args=(config,), daemon=True)
        thread.start()
        
    # 資産評価用のバックグラウンドスレッドも起動
    self.portfolio_thread = threading.Thread(target=self._run_portfolio_monitor, daemon=True)
    self.portfolio_thread.start()

これにより、仮想通貨のような動きの速い市場に対しても、他のエージェントの影響を受けずに即座に反応できるようになりました。

改善ポイント2: ログ表示のグリッド化

並列化に伴い、ログも混ざってしまうと見づらいため、フロントエンド(React)の表示を一新しました。
これまでの「タブ切り替え」方式をやめ、3つのエージェントのログを横並び(グリッド)で同時表示するようにしました。

変更後のUI

  • 上段: システム全体の通知(System Notification)
  • 下段: 3カラム構成で各エージェントのログを表示
    • JP Agent (日本株)
    • US Agent (米国株)
    • Crypto Agent (仮想通貨)
/* frontend/src/AgentPanel.css */
.agents-logs-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr); /* 3等分 */
  gap: 15px;
}

まとめ

今回のアップデートで、システムがより「マルチエージェント」らしくなりました。
画面上で3つのAIがそれぞれ独立して市場を監視し、判断を下している様子を眺めるのは、開発者として非常にワクワクします。

次は、各エージェント間の連携(例:米国株の暴落を検知したら、日本株エージェントも警戒モードに入るなど)を実装していきたいと考えています。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?