Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GraphAI - Full-Stack TypeScript Tool for AI App...
Search
Isamu Arimoto
November 23, 2024
Technology
500
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GraphAI - Full-Stack TypeScript Tool for AI Applications
Isamu Arimoto
November 23, 2024
More Decks by Isamu Arimoto
See All by Isamu Arimoto
MulmoCast
isamu
0
11
GraphAI
isamu
0
430
Other Decks in Technology
See All in Technology
モノリス Rails でも日中に rails db:migrate を走らせたい! / Daytime rails db:migrate on Monolithic Rails!
euglena1215
4
580
Bits AI を制するものは Datadog を制す / The player that controls Bits AI, controls Datadog
kaminashi
0
100
Goでデータパイプラインを作ろう
sansantech
PRO
1
450
Service Connect 上のサービスに ECS Service の外側から到達できなかった話
ota1022
1
250
メルカリのグローバルアプリで挑んだ AlloyDB 運用と課題解決の実践記
hatappi
0
250
FDEの心得
noriakioji
4
5.9k
トヨタ⽣産⽅式(TPS)⼊⾨
recruitengineers
PRO
3
830
強化学習「理論」入門
enakai00
3
3.6k
Forza Horizon 6 のテレメトリ機能で 自動運転に使えそうな学習データを集める話
henjin0
0
180
今こそ聞きたいソフトウェア設計 ドメイン駆動設計再入門
masuda220
PRO
17
7.3k
AWS ネットワーク構築でハマった(ハマりかけた) 5選とそこから得た教訓
nagisa53
4
220
第3回しろおびセキュリティスポンサーセッション
log0417
0
200
Featured
See All Featured
The Limits of Empathy - UXLibs8
cassininazir
1
600
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
340
First, design no harm
axbom
PRO
2
1.2k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
240
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
790
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
620
Information Architects: The Missing Link in Design Systems
soysaucechin
0
1.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Scaling GitHub
holman
464
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
490
Transcript
GraphAI Full-Stack TypeScript Tool for AI Applications Isamu Arimoto by
Receptron team
自己紹介 Isamu Arimoto Software engineer Server/Web Singularity Society Fully-On-Chain SVG
2 NFT https://opensea.io/collection/lai dback-lu おもちかえり.com bus2.0 SlashGPT/GraphAI GraphAI by Receptron team 2
Contents 内容 GraphAI 特徴 as Full-Stack TypeScript AI GraphAI を試す方法
ツールや各種情報 GraphAI の未来 発表しないこと Agent の作り方 GraphData の作り方 マルチエージェントの作り方 GraphAI by Receptron team 3
GraphAI 特徴 背景 非同期処理 ML,LLM はPython に任せてAPI 経由で! 全部TypeScript で書きたい
FullStack TypeScript AI!! TypeScript Write once run anywhere ブラウザ、サーバ、バッチ、cli GraphAI by Receptron team 4
GraphAI とAgent Graph Graph とAgent GraphAI 本体はシンプル Graph の制御のみ Agent
- LLM/WebAPI/ データ処理/IO Agent Filter - 各Agent を実行する前後に処理を挟む GraphAI by Receptron team 5
GraphAI 特徴 GraphAI からAgent の呼び出し js のAPI で呼び出す http でサーバのAPI
を呼び出す GraphData, Agent はサーバ/ クライアントで同じコ ード 環境依存なもの 秘匿API key の必要な処理/CORS DB / Python の処理 ユーザからの入力 どのAgent/Node をどのサーバで動かすか設定可能 変更もすぐにできる express + middleware(@receptron/graphai_express) GraphAI by Receptron team 6
GraphAI を動かす構成 * Server / Batch / Browser Server Client
Agent の呼び出しはjs のapi Agent をhttp で呼び出す GraphAI by Receptron team 7
GraphAI を動かす構成 Server 分散 Server Local 混在 GraphAI by Receptron
team 8
GraphAI を動かす構成 内外Server サブグラフ GraphAI by Receptron team 9
GraphAI 特徴 Agent はjs のapi でもhttp でもOK 渡すデータは共通 http であればAgent
はTypeScript でなくても良い。 サーバでPython/Go/Rust/Ruby のAgent js でmock agent を作っておくと便利 Streaming もサポート どの構成でも、ほとんど同じように動く cli/ ブラウザ 環境に合わせて柔軟な組み合わせが可能 開発、ブラウザで動作、サーバクライアントで動作をシームレス GraphAI by Receptron team 10
GraphAI 特徴 JS API export const arrayJoinAgent = async ({
namedInputs, params }) => { const { separator } = params; return { text :namedInputs.array.join(separator ?? "") }; }; HTTP Request body { namedInput: {array: ["1", "2", "3"]}, params: { separator: "-" }} Response { text: "1-2-3" } GraphAI by Receptron team 11
さて、どうやって試す? codePen/html 11/14 から対応中。ちょっと動く。jsdelivr でumd 配布 https://codepen.io/isamua/pen/YzmgRYg html https://github.com/receptron/graphai/tree/main/packages/samples/htmlSample openAIFetchAgent
cli npm package + sample graph file web Vue.js での実装サンプル TypeScript GraphAI レポジトリのtest/sample zenn の記事 GraphAI by Receptron team 12
Agent * npm で提供 llmAgent openaiAgent / groqAgent / anthropicAgent
/ geminiAgent arrayAgent pop / push / shift / join / flat dataAgent copy / merge / sum / propertyFilter / total graphAgent nestedAgent mapAgent GraphAI by Receptron team 13
CLI で動かす CLI でコマンドとして Agent は全部入り GraphData はYAML/JSON のファイルを渡す install
npm install -g @receptron/graphai_cli GraphData のサンプル(yaml, json) をダウンロード https://github.com/receptron/graphai/tree/main/packages/samples/graph_data .env OPENAI_API_KEY=sk-xxx run graphai ${file.yaml/json} GraphAI by Receptron team 14
CLI で動かす graphai <yaml_or_json_file> run GraphAI with GraphAI file. Positionals:
--yaml_or_json_file yaml or json file [文字列] オプション: --help ヘルプを表示 [真偽] --version バージョンを表示 [真偽] -l, --list agents list -s, --sample agent sample data [文字列] -d, --detail agent detail [文字列] -v, --verbose verbose log [真偽] [必須] [デフォルト: false] -a, --all all result [真偽] [必須] [デフォルト: false] -m, --mermaid mermaid [真偽] [必須] [デフォルト: false] --yaml dump yaml [真偽] [必須] [デフォルト: false] --json dump json [真偽] [必須] [デフォルト: false] --log output log [文字列] GraphAI by Receptron team 15
Sample の紹介 https://github.com/receptron/graphai/tree/main/packages/samples/graph_data/openai business_idea_jp.yaml 事業アイデアを出して評価(map) chat.yaml シンプルなAI とのチャット(loop) interview.yaml 指定した有名人にインタビュー(history)
reception.yaml 氏名、生年月日、性別を尋ねる(tools) metachat.yaml reception.yaml を元にGraphData 生成(interpreter) weather.yaml API を使って天気を調べる(nested graph) GraphAI by Receptron team 16
TypeScript での動かし方 * 必要なパッケージのインストール yarn add graphai yarn add @graphai/agents
コード import { GraphAI } from "graphai"; import * as agent from "@graphai/agents"; const graphData = {...}; const main = async () => { const graphai = new GraphAI(graphData, agents); const ret = await graphai.run(); console.log(ret); }; main(); GraphAI by Receptron team 17
Web(vue) で動かす https://github.com/receptron/graphai-demo-web/ (vue) ほとんどのサンプルがvue のフロントだけで動く https://github.com/receptron/graphai-agent-server (express) サンプルサーバ GraphAI
by Receptron team 18
Streaming の実装方法 Agent for await (const message of chatStream) {
const token = message.choices[0].delta.content; if (filterParams && filterParams.streamTokenCallback && token) { filterParams.streamTokenCallback(token); } } Clent const outSideFunciton = (context: AgentFunctionContext, data: string) => { const nodeId = context.debugInfo.nodeId; streamData[nodeId] = (streamData[nodeId] || "") + data; }; const agentFilters = [{ name: "streamAgentFilter", agent: streamAgentFilterGenerator<string>(outSideFunciton), }]; GraphAI by Receptron team 19
npm * graphai 本体 @graphai/*_agents 単機能のごとに1つのnpm=agent / 依存関係を減らす目的 @graphai/vanilla -
npm の依存のないagent @graphai/llm_agents - openAIAgent, groqAgent などのメタパッケージ @graphai/agents - 全部入りメタパッケージ @graphai/agent_filters @receptron/* ツール郡 graphai_cli, graphai_express, GraphAI by Receptron team 20
npm * 目的 パッケージ cli 利用 @receptron/graphai_cli TypeScript で動かす*1 graphai,
@graphai/agents TypeScript でstreaming *1 + @graphai/agent_filters AgentServer(streaming) @receptron/graphai_express, @graphai/agents @graphai/agents は個別のagent でもOK AgentServer はGraphAI 不要 Server はAPI が一致していれば言語不問 inputs/params/result GraphAI by Receptron team 21
git の構成 本家レポジトリはモノレポ https://github.com/receptron/graphai packages GraphAI 本体/ サンプル/ 各種ツール/document generator/
agent filter agent 各種Agent llm_agents llm のagents yaml の純粋なサンプル https://github.com/receptron/graphai_samples express/cytoscape receptron/graphai-utils GraphAI by Receptron team 22
git の構成 Vue のデモ https://github.com/receptron/graphai-demo-web Python のAgent サーバサンプル https://github.com/receptron/graphai-python-server Agent
Server(sample) https://github.com/receptron/graphai-agent-server agents + express の実装例 GraphAI by Receptron team 23
Document 公式レポジトリのTOP からリンク zenn でGraphAI https://zenn.dev/topics/graphai?order=latest GraphAI by Receptron team
24
Express Server(API) AgentFunctionInfo を元に、サーバが提 供できるAPI 一覧 将来的に、これらの情報を使って、動的 にAgent を利用できる仕組みを提供 メタAPI
Info Server Agent 分散 + AI によるGraphData の自動 生成 GraphAI by Receptron team 25
Future 世界中のAgent を使ったDynamic multi-agent 要素技術 metachat.html - 動的にGraphData を作る agent
server agent のmetainfo + agent api 世界中のAgent のAPI List Agent を検索する仕組み Agent を探すAgent Web3 ?? Agent に対する報酬( 課金)/ 信頼性の評価 GraphAI by Receptron team 26
まとめ GraphAI は、サーバ、クライアントの構成自由自在 いろいろな方法で試せる 試して、フィードバックください GraphAI by Receptron team 27
Thank you!! GraphAI by Receptron team 28
Agent * 一覧 https://github.com/receptron/graphai/t ree/main/docs/agentDocs llmAgent openaiAgent / groqAgent /
anthropicAgent / geminiAgent arrayAgent pop / push/shift / join / flat dataAgent copy / merge / sum /propertyFilter / total graphAgent GraphAI by Receptron team 29
graphAgent nestedAgent Agent 内でGraphAI を実行 loop と組み合わせることで多様な処理 loop - Graph
全体を繰り返す(n 回 or 条件を満たすまで) Chat でユーザからの入力が条件を満たすまで Funciton calling の結果がとれるまで Code を実行するAgent と組み合わせて、正しい処理が終わるまで mapAgent 同じ処理に別々のデータを渡して並列。 アイデアを10 個出す それぞれのアイデアを評価 GraphAI by Receptron team 30
GraphData の作り方 * 必要なAgent を探す inputs でつなげる 走らせる 最初は全てnode の結果を受け取る
graphai.run(true) const main = async () => { const graphai = new GraphAI(graphData, agents); const logger = (log, __isUpdate) => { console.log(log)}; graphai.onLogCallback = logger; const ret = await graphai.run(true); console.log(ret); }; main(); GraphAI by Receptron team 31
inputs * 前のNode の結果を受け取る 依存/Agent に渡す値 Graph を作るときに一番ハマるポイ ント inputs:
Record<string, unknown> :nodeId.props.props.function().function() 前のNode の結果&Node の入力の形式 結果: nodeA: { array: ["foo", "bar"]} inputs: { text: ":nodeA.array.join() } array には array.$0 array.$1 graph_agent には見えないStaticNode が ある mapAgent rows -> row nested inputs がstatic node に GraphAI by Receptron team 32
props function inputs で使える関数 :node.array_data.length() T.B.D. GraphAI by Receptron team
33
Agent の作り方 agent/agentFunction/Sample & UnitTest 関数を作る AgentFunctionInfo でwrap (ts の場合、agent
に即時関数を渡す裏技もある) agent: (namedInputs) => { console.log(namedInputs); return true;} AgentFunctionInfo のsample でunit test Repositories Sample のAgent を作る https://github.com/isamu/graphai_agent_template Sample のAgent を作る( モノレポ) https://github.com/isamu/graphai-agents/tree/main/packages テストランナー https://github.com/isamu/graphai_agent_test_runner GraphAI by Receptron team 34
AgentFunctionInfo // Params, result, input(array), namedInput(record) export const dataSumTemplateAgent: AgentFunction<Record<never,
never>, number, number> = async ({ inputs }) => { return inputs.reduce((tmp, input) => { return tmp + input; }, 0); }; const dataSumTemplateAgentInfo: AgentFunctionInfo = { name: "dataSumTemplateAgent", agent: dataSumTemplateAgent, samples: [ { inputs: [1, 2], params: {}, result: 3, }, ], description: "Returns the sum of input values", category: ["data"], author: "Satoshi Nakajima", repository: "https://github.com/receptron/graphai", license: "MIT", }; export default dataSumTemplateAgentInfo; agent の本体と、agent に関する情報 UnitTest の自動化/Document の自動化/http でのAPI Info GraphAI by Receptron team 35
ユーティリティ Agent テスト AgentFunctionInfo を使ってUnit Test TDD Agent のdoc document
の自動生成 express server のmiddleware すぐにサーバ、クライアント構成ができる GraphAI by Receptron team 36
AgentFilter 各Agent を実行する前後に処理を挟む express のmiddleware, Rails のaround filter agentId, nodeId
単位で動作の有無を定義 例 サーバへ処理をバイパス キャッシュ ログ streaming GraphAI by Receptron team 37
GraphData/Agent の説明 * Graph Graph = Graph theory のグラフ Node
とEdge(inputs) で構成/ 有向非巡回グラフ Graph の定義では非巡回だがLoop 処理は可能( 全体を繰り替えす) NestedGraph で、局所的にLoop も可能 JSON/YAML/TypeScript の構造化データ(GraphData と呼びます) 最初に入力がないNode が実行される そのNode の動作が完了したら、そのNode の結果を受け取る次のNode が実行される GraphAI by Receptron team 38
GraphData * llm/template がNode inputs の:llm がEdge(Source がllm でTarget がtemplate)
{ "version": 0.5, "nodes": { "userInputs": { "agent": "textInputAgent", "params": { "message": "You:" } }, "llm": { "agent": "openAIAgent", "params": {"system": "You are a cat. Your name is Neko."}, "inputs": { "prompt": ":userInputs"} }, "template": { "agent": "stringTemplateAgent", "params": {"template": "${message}"}, "inputs": {"message": ":llm.text"}, "isResult": true } } } GraphAI by Receptron team 39
GraphAI って? * GraphAI 本体はNode とInputs の管理とタスクの管理のみ GraphAI 本体自体はAgent は持っていない
コンストラクタにGraphData と共に、agents や、agent filter を渡す GraphAI 本体とは別にAgent を配布している 単体パッケージ多数 Agent は必要なものだけ渡せる 自作Agent と配布されているAgent を一緒に使える GraphAI by Receptron team 40
TypeScript での動かし方( サンプル) * yarn のscript - https://github.com/receptron/graphai/tree/main/packages/samples yarn run
sample src/llm/interview_jp.ts Web(vue) - https://github.com/receptron/graphai-demo-web/ yarn install yarn serve ai-scientist-ts - https://github.com/isamu/ai-scientist GraphAI by Receptron team 41