Yapay Zeka Ajanı Oluşturma
Bu öğreticide bir çalışma alanı içinde yapay zeka ajanı oluşturacak, bir çalıştırma başlatacak ve sonuçları inceleyeceksiniz. Sonunda görevleri otonom olarak işleyebilen çalışan bir ajana sahip olacaksınız.
Ön Koşullar
- Geçerli bir erişim token'ına sahip bir Chainabit hesabı
- Terminalinizde
curlkullanılabilir olmalı - Mevcut bir çalışma alanı (bkz. Çalışma Alanları API (EN))
Ortam değişkenlerinizi ayarlayın:
bash
export TOKEN="your-access-token"
export WORKSPACE_ID="ws_01HQ..."Adım 1: Ajan Tanımı Oluşturma
Çalışma alanınızda yeni bir yapay zeka ajanı tanımlayın. Ajan tanımı, ajanın ne yaptığını ve nasıl davrandığını açıklar:
bash
curl -s -X POST "https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/agents" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Daily Summary Agent",
"description": "Generates a daily summary of completed activities",
"instructions": "Analyze the user'\''s completed bits for today and produce a concise summary with highlights and suggestions.",
"modelId": "model_01HQ..."
}'javascript
const res = await fetch(`https://api.chainabit.com/api/v1/workspaces/${WORKSPACE_ID}/ai/agents`, {
method: 'POST',
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Daily Summary Agent',
description: 'Generates a daily summary of completed activities',
instructions:
"Analyze the user's completed bits for today and produce a concise summary with highlights and suggestions.",
modelId: 'model_01HQ...',
}),
});
const data = await res.json();
console.log(data);python
import requests
res = requests.post(
f"{BASE}/workspaces/{WORKSPACE_ID}/ai/agents",
headers={
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json",
},
json={
"name": "Daily Summary Agent",
"description": "Generates a daily summary of completed activities",
"instructions": "Analyze the user's completed bits for today and produce a concise summary with highlights and suggestions.",
"modelId": "model_01HQ...",
},
)
print(res.json())Yanıt:
json
{
"data": {
"id": "agent_01HQA...",
"workspaceId": "ws_01HQ...",
"name": "Daily Summary Agent",
"description": "Generates a daily summary of completed activities",
"status": "active",
"createdAt": "2026-03-17T10:00:00.000Z"
}
}Ajan kimliğini kaydedin:
bash
export AGENT_ID="agent_01HQA..."Adım 2: Ajanı Çalıştırma
Ajan için bir çalıştırma başlatın. Ajanın işleme sırasında kullanacağı giriş parametreleri geçirebilirsiniz:
bash
curl -s -X POST "https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/agents/$AGENT_ID/runs" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"input": {
"date": "2026-03-17"
}
}'javascript
const res = await fetch(
`https://api.chainabit.com/api/v1/workspaces/${WORKSPACE_ID}/ai/agents/${AGENT_ID}/runs`,
{
method: 'POST',
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
input: { date: '2026-03-17' },
}),
},
);
const data = await res.json();
console.log(data);python
res = requests.post(
f"{BASE}/workspaces/{WORKSPACE_ID}/ai/agents/{AGENT_ID}/runs",
headers={"Authorization": f"Bearer {TOKEN}"},
json={"input": {"date": "2026-03-17"}},
)
print(res.json())Yanıt:
json
{
"data": {
"id": "run_01HQB...",
"agentId": "agent_01HQA...",
"status": "running",
"createdAt": "2026-03-17T10:05:00.000Z"
}
}Çalıştırma kimliğini kaydedin:
bash
export RUN_ID="run_01HQB..."Adım 3: Çalıştırma Sonuçlarını Kontrol Etme
Çalıştırma tamamlanana kadar durumu sorgulayın, ardından çıktıyı alın:
bash
curl -s "https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/agents/$AGENT_ID/runs/$RUN_ID" \
-H "Authorization: Bearer $TOKEN"javascript
const res = await fetch(
`https://api.chainabit.com/api/v1/workspaces/${WORKSPACE_ID}/ai/agents/${AGENT_ID}/runs/${RUN_ID}`,
{
headers: { Authorization: `Bearer ${TOKEN}` },
},
);
const data = await res.json();
console.log(data);python
res = requests.get(
f"{BASE}/workspaces/{WORKSPACE_ID}/ai/agents/{AGENT_ID}/runs/{RUN_ID}",
headers={"Authorization": f"Bearer {TOKEN}"},
)
print(res.json())Yanıt:
json
{
"data": {
"id": "run_01HQB...",
"agentId": "agent_01HQA...",
"status": "completed",
"output": {
"summary": "You completed 4 out of 5 bits today. Highlights: Running streak extended to 7 days. Suggestion: Try adding a 5-minute meditation to your morning routine.",
"completedBits": 4,
"totalBits": 5
},
"tokensUsed": 284,
"completedAt": "2026-03-17T10:05:12.000Z"
}
}Ajan Yaşam Döngüsü
Özet
Bu öğreticide şunları yaptınız:
- Bir çalışma alanında yapay zeka ajan tanımı oluşturdunuz
- Giriş parametreleriyle bir ajan çalıştırması başlattınız
- Tamamlanan çalıştırma sonuçlarını aldınız
Sonraki Adımlar
- Zincir Tetikleyicileri (EN) — ajan zincirlerini (iş akışlarını) cron/olay tetikleyicileriyle çalıştırma
- Agents API Referansı — tam endpoint dokümantasyonu