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
480
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
7
GraphAI
isamu
0
400
Other Decks in Technology
See All in Technology
なぜ私たちのSREプラクティスはなかなか機能しないのか 〜システムより先に組織を見る〜 / Why our SRE practices aren't really working
vtryo
1
1.6k
なぜ人は自分のプロジェクトを 「なんちゃってアジャイル」と 自嘲するのか
kozotaira
0
260
プライバシー保護の理論と実践
lycorptech_jp
PRO
1
240
AI時代のエンジニアキャリアについて今一度考える
sakamoto_582
1
1.3k
プロダクトだけじゃない、社内プロセスにおける自動化・省力化ノススメ
kakehashi
PRO
1
1.5k
Foxgloveについて 実際にExtensionを開発して公開するまでの話 / About Foxglove: The Story of Developing and Releasing an Extension
ry0_ka
0
170
“ID沼入口” - 基本とセキュリティから始める、考え続けるためのID管理技術勉強会 告知&イントロ
ritou
0
430
Claude Codeとハーネスについて考えてみる
oikon48
18
8.7k
小さいから、全部わかる。— 常駐AI "xangi" のすすめ
sugupoko
0
270
CSに"SLO"は要らない、経営層に"99.9%"は伝わらない - SREを全社に"翻訳"する3原則
cscengineer
PRO
0
2.6k
背中から、背中へ /paying forward to community
naitosatoshi
0
230
LiDAR SLAMの実装とセンサ融合 ~Lie群からContinuous-Time LIOまで~
naokiakai
1
990
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
Exploring anti-patterns in Rails
aemeredith
3
440
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
340
The Spectacular Lies of Maps
axbom
PRO
1
850
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
550
Believing is Seeing
oripsolob
1
160
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
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