-
-
Save mackee/91e9bf49e69d9324f32b43fa5cb8cecb to your computer and use it in GitHub Desktop.
yapcfukukoka2025-road-to-agent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!perl | |
| use v5.34; | |
| use utf8; | |
| use constant { | |
| MODEL => "Qwen3-Coder-480B-A35B-Instruct-FP8", | |
| ENDPOINT => "https://api.ai.sakura.ad.jp/v1/chat/completions", | |
| MAX_TOKENS => 100_000, | |
| }; | |
| use Encode qw/decode_utf8 encode_utf8/; | |
| use Capture::Tiny qw/capture/; | |
| use Term::ANSIColor qw/colored/; | |
| use HTTP::Tinyish; | |
| use JSON::PP; | |
| my $task = decode_utf8($ARGV[0] // ""); | |
| if (!$task) { | |
| die "タスクを指定してください。\n"; | |
| } | |
| my @messages = ( | |
| { role => "system", content => "あなたはなんでもPerlで解決してしまう親切なAIアシスタントです" }, | |
| { | |
| role => "user", | |
| content => <<~"EOM" | |
| あなたのタスク: $task, 3つのbacktickで囲まれたコードブロック内にPerlのコードを使って返信してください。 | |
| コードブロック内をevalで実行した際の標準出力があなたに渡されます。 | |
| あなたはコードを繰り返し実行して、その結果を読み取り、さらに必要があれば結果を元にコードを生成します。タスクが完了するまで繰り返します。 | |
| もしタスクが完了した時、コードブロックを実行した際の**標準出力の最初の行**に"__COMPLETE__"を出力してください。ユーザーにはその後の行が最終結果として表示されます。 | |
| Perlコードブロックの前にはTHOUGHTセクションを追加し、推論プロセスを説明してください。 | |
| 以下の<format_example>セクションに示すようなフォーマットにしてください。 | |
| <format_example> | |
| THOUGHT: Your reasoning and analysis here | |
| ```perl | |
| # Your Perl code here | |
| ``` | |
| この形式の応答に従わない場合は、あなたの応答は拒否されます。 | |
| EOM | |
| } | |
| ); | |
| while () { | |
| my $choice = chat_completion(\@messages); | |
| my $content = $choice->{message}->{content}; | |
| say colored(["grey8"], encode_utf8($content)); | |
| if ($content =~ /```(?:perl)?\n(.*)\n```/ms) { | |
| my $code = $1; | |
| say colored(["green"], encode_utf8("実行中:")); | |
| my ($result) = capture { | |
| eval $code; | |
| }; | |
| $result = decode_utf8($result); | |
| say colored(["blue"], encode_utf8($result)); | |
| if ($@) { | |
| my $error = "コードの実行中にエラーが発生しました: $@"; | |
| say colored(["red"], $error); | |
| push @messages, { | |
| role => "user", | |
| content => <<~"EOM" | |
| コードの実行中にエラーが発生しました: $error | |
| EOM | |
| }; | |
| next; | |
| } | |
| my $output = $result =~ s/^__COMPLETE__\n//smr; | |
| if ($output ne $result) { | |
| say encode_utf8($output); | |
| push @messages, { | |
| role => "assistant", | |
| content => $content, | |
| }, | |
| { | |
| role => "user", | |
| content => $result, | |
| }, | |
| { | |
| role => "assistant", | |
| content => $output, | |
| }; | |
| last; | |
| } | |
| else { | |
| push @messages, | |
| { | |
| role => "assistant", | |
| content => $content, | |
| }, | |
| { | |
| role => "user", | |
| content => $result, | |
| }; | |
| } | |
| } | |
| else { | |
| push @messages, { role => "assistant", content => $content }; | |
| last; | |
| } | |
| } | |
| sub chat_completion { | |
| my $messages = shift; | |
| my $sakura_ai_api_key = $ENV{SAKURA_AI_API_KEY} // die "Please set SAKURA_AI_API_KEY environment variable"; | |
| my $http = HTTP::Tinyish->new(agent => "Sigil/0.1"); | |
| my $req = { | |
| model => MODEL, | |
| messages => $messages, | |
| max_tokens => MAX_TOKENS, | |
| temperature => 0.0, | |
| tool_choice => "none", | |
| tools => [], | |
| stream => JSON::PP::false, | |
| }; | |
| my $req_json = JSON::PP->new->utf8->encode($req); | |
| my $resp = $http->post(ENDPOINT, { | |
| headers => { | |
| "Content-Type" => "application/json", | |
| "Authorization" => "Bearer " . $sakura_ai_api_key, | |
| }, | |
| content => $req_json, | |
| }); | |
| my $decoded = JSON::PP->new->utf8->decode($resp->{content}); | |
| if (exists $decoded->{error}) { | |
| die "Error: " . $decoded->{error}->{message} . "\n"; | |
| } | |
| my $choice = $decoded->{choices}->[0]; | |
| return $choice; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!perl | |
| use strict; | |
| use warnings; | |
| use utf8; | |
| my $problem = `jq 'select(.instance_id=="django__django-11299").problem_statement' -r /out/swe_verified.jsonl`; | |
| my $instructions = ' | |
| <pr_description> | |
| 次のPullRequestの説明を検討してください:'.$problem.<<'EOM' | |
| </pr_description> | |
| <instructions> | |
| # タスクの指示 | |
| ## 概要 | |
| あなたは、コマンドを送信することでコンピューターと継続的にやり取りするソフトウェアエンジニアです。 | |
| PR の説明に記載されている要件を満たすために必要な変更の実装を支援します。 | |
| 具体的には、PR の説明に記載されている問題を、コードベースと一貫性を保ちつつ、一般的な方法で修正するために、現在のディレクトリにあるテストファイル以外のファイルに変更を加えることがあなたの仕事です。 | |
| IMPORTANT: これは、1 つのPerlコードを考えて記述しし、その実行結果を確認してから、次のPerlコードを考えて記述し実行するという対話型のプロセスです。 | |
| 各回答について: | |
| 1. あなたの推論とあなたが達成しようとしていることを説明する THOUGHT セクションを含めます | |
| 2. 実行するPerlコードを1つだけ記述する | |
| ## Important Boundaries | |
| - MODIFY: /testbed 内の通常のソースコード ファイル (これは、後続のすべてのコマンドの作業ディレクトリです) | |
| - DO NOT MODIFY: テスト、構成ファイル (pyproject.toml、setup.cfg など) | |
| ## 推奨するワークフロー | |
| 1. 関連するファイルを見つけて読み取ることでコードベースを分析する | |
| 2. 問題を再現するスクリプトを作成する | |
| 3. ソースコードを編集して問題を解決する | |
| 4. スクリプトを再度実行して修正が機能することを確認する | |
| 5. エッジケースをテストして、修正が堅牢であることを確認する | |
| ## Perl 実行ルール | |
| You are operating in an environment where | |
| 1. あなたは必ず一つのPerlコードを実行します | |
| 2. システムはそのPerlコードをevalで実行します | |
| 3. あなたはevalで実行された際の標準出力を受け取ります | |
| 4. あなたはその出力を見て、次のPerlコードを考え、再び実行します | |
| 各回答には以下を含める必要があります: | |
| 1. 1つの **THOUGHT** セクションをあなたの推論を説明するために記述します | |
| 2. 1つのPerlコードブロックを記述します | |
| あなたのレスポンスの例: | |
| <format_example> | |
| THOUGHT: ここでは私の推論プロセス、現状の分析、 | |
| そして、以下のPerlコードで何を実現しようとしているのか。 | |
| ```perl | |
| your_perl_code_here | |
| ``` | |
| </format_example> | |
| コードは単一のPerlコードブロックで指定する必要があります: | |
| ```bash | |
| your_perl_code_here | |
| ``` | |
| **重要な要件:** | |
| - 回答には、理由を説明する「考え」セクションを含める必要があります。 | |
| - 回答には、必ず1つのPerlコードブロックを含める必要があります。 | |
| - Perlブロックを0個以上含めた場合、またはコードを全く含めなかった場合、回答は不合格となります。 | |
| - 1つの回答で、複数の独立したPerlコードを別々のコードブロックで実行しないでください。 | |
| - ディレクトリまたは環境変数の変更は永続的ではありません。すべてのアクションは新しいサブシェルで実行されます。 | |
| - ただし、openや%ENVからファイルから環境変数の書き込み/読み込みを行ったりすることは可能です。 | |
| 正しい回答の例: | |
| <example_response> | |
| THOUGHT: まずリポジトリの構造を理解する必要があります。コードベースをより深く理解するために、現在のディレクトリにどのようなファイルがあるか確認させてください。 | |
| ```perl | |
| use Path::Tiny qw/path/; | |
| my @paths = path("/tmp")->children; | |
| for my $p (@paths) { | |
| print $p->basename."\n"; | |
| } | |
| ``` | |
| </example_response> | |
| 悪い回答の例: | |
| <example_response> | |
| THOUGHT: コードベースを調べて特定のファイルを確認する必要があります。そのためには複数のコマンドを実行します。 | |
| ```perl | |
| use Path::Tiny qw/path/; | |
| my @paths = path("/tmp")->children; | |
| for my $p (@paths) { | |
| print $p->basename."\n"; | |
| } | |
| ``` | |
| ではファイルを読んでみます: | |
| ```perl | |
| use Path::Tiny qw/path/; | |
| my $file = path("/tmp/somefile.txt")->slurp_utf8; | |
| print $file."\n"; | |
| ``` | |
| </example_response> | |
| 複数のPerlブロックで実行することは避けて1つのPerlブロックにまとめてください | |
| ## 環境の詳細 | |
| - あなたはLinuxシステムで作業しています | |
| - Perlはv5.34.0です。PerlモジュールPath::Tinyが利用可能です | |
| - もし必要なモジュールがない場合は、cpanmを使ってインストールできます | |
| <examples_of_installing_modules> | |
| THOUGHT: Webリクエストを行うためのモジュールLWP::UserAgentが必要です。cpanmを使ってインストールします。 | |
| ```perl | |
| system("cpanm LWP::UserAgent"); | |
| ``` | |
| ## 有用なPerlコードリファレンス | |
| ### 新規ファイルの作成: | |
| ```perl | |
| use Path::Tiny qw/path/; | |
| path("newfile.py")->spew_utf8(<<'EOF'); | |
| import numpy as np | |
| hello = "world" | |
| print(hello) | |
| EOF | |
| ``` | |
| ### ファイルの書き換え: | |
| ```perl | |
| # Replace all occurrences | |
| my $file = path("filename.py"); | |
| my $content = $file->slurp_utf8; | |
| $content =~ s/old_string/new_string/g; | |
| $file->spew_utf8($content); | |
| ``` | |
| ```perl | |
| # Replace only first occurrence | |
| my $file = path("filename.py"); | |
| my $content = $file->slurp_utf8; | |
| $content =~ s/old_string/new_string/; | |
| $file->spew_utf8($content); | |
| ``` | |
| ```perl | |
| # Replace first occurrence on line 1 | |
| use Path::Tiny qw/path/; | |
| my $file = path("filename.py"); | |
| my @lines = $file->lines_utf8; | |
| $lines[0] =~ s/old_string/new_string/; | |
| $file->spew_utf8(join("", @lines)); | |
| ``` | |
| ```perl | |
| # Replace all occurrences in lines 1-10 | |
| use Path::Tiny qw/path/; | |
| my $file = path("filename.py"); | |
| my @lines = $file->lines_utf8; | |
| for my $i (0..9) { | |
| $lines[$i] =~ s/old_string/new_string/g; | |
| } | |
| $file->spew_utf8(join("", @lines)); | |
| ``` | |
| ### ファイルの読み取り: | |
| ```perl | |
| # View specific lines with numbers | |
| use Path::Tiny qw/path/; | |
| my $file = path("filename.py"); | |
| my @lines = $file->lines_utf8; | |
| for my $i (9..19) { | |
| print $lines[$i]; | |
| } | |
| ``` | |
| ``` | |
| ## タスク完了の手順 | |
| 作業(読み取り、編集、テスト)が完了し、それ以上進めなくなったら、 | |
| 次のコードを正確に実行してください。 | |
| ```perl | |
| system("git add -A"); | |
| system("git diff --cached"); | |
| print "__COMPLETE__\n"; | |
| ``` | |
| このコマンドは作業を送信します。 | |
| 送信後は、このタスクでいかなる作業(読み取り、編集、テスト)も続行できません。 | |
| </instructions> | |
| EOM | |
| ; | |
| open my $fh, '>:encoding(UTF-8)', '/out/instructions.txt' or die $!; | |
| print $fh $instructions; | |
| close $fh; | |
| system("perl", "-I/out/local/lib/perl5", "/out/agents.pl", "/out/instructions.txtを読み取ってタスクを完了してください"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -ex | |
| exec docker run --rm -it --env SAKURA_AI_API_KEY --name swe-django-11299 \ | |
| -v "$PWD":/out \ | |
| ghcr.io/epoch-research/swe-bench.eval.arm64.django__django-11299:latest \ | |
| /out/run.pl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment