나_노 코딩 에이전트
결론
Bash만 쥐어줘도 일단 hello world 수준의 코드는 작성할 수 있긴 하다.
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText, type ModelMessage } from 'ai';
import { z } from 'zod';
import { bashTool } from './tool/bash';
const model = createOpenAICompatible({
name: 'opencode',
baseURL: 'https://gateway.opencode.ai/v1',
apiKey: '',
})('grok-code');
async function main() {
// Read user prompt from stdin or pipe
const stdin = Bun.stdin.stream();
const reader = stdin.getReader();
const { value } = await reader.read();
const userPrompt = new TextDecoder().decode(value).trim();
let messages: Array<ModelMessage> = [];
messages = [
{ role: "system", content: "You are helpful AI assistant specialized in coding.", },
{ role: "user", content: userPrompt, }
];
const result = await generateText({
model,
messages,
tools: { bash: bashTool, read: readTool, edit: editTool, },
stopWhen: async (_calls) => false,
});
console.log('Response:', result.text, result.reasoning, result.finishReason);
}
main();
tool/bash.ts의 구현도 대충 50줄 정도 있는데 중요한 것은 아니니 패스…
문제
claude code pro의 구독이 어제 끝났는데, 마침 Grok code fast 모델이 기간한정무료로 배포되었기 때문에 해당 모델을 최대한 우려먹을 방법을 찾다가 한번 Self 툴 생성 아이디어도 구현해볼 겸 해서 최소한의 코딩 에이전트를 직접 만들어보기로 했다.
오늘의 목표
echo “Create a hello world program in Python named hello.py” | bun index.ts
발견한 것들
Opencode에서 Grok code 때문에 새로 endpoint를 만들었고, 아무 인증이 없기 때문에 자유롭게 쓸 수 있다. (단, opencode의 endpoint를 사용하기 때문에 사용 기록은 저쪽에 남는다. user agent 등이 문제가 될 수 있을것)
@ai-sdk
는 꽤 괜찮다. description, inputSchema, execute 정도의 간단한 인터페이스만 구현해서 넘겨줘도
적절한 integration을 해 줘서 쓰기가 편하다. 몰랐을면 OpenAI API에 맞춰서 tool 연결한다고 한참 고생했을 것.