> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# रनटाइम टूल से कोड-रिव्यू एजेंट चलाएँ

> स्थानीय रनटाइम टूल, सख्त JSON और मानव अनुमोदन चेकपॉइंट की मदद से फिर से शुरू किया जा सकने वाला कोड-रिव्यू workflow बनाएँ।

जब किसी workflow को ये काम करने हों, तब यह तरीका अपनाएँ:

* स्थानीय रनटाइम टूल से कोड-संबंधी संदर्भ की जाँच करना
* खुली prosa के बजाय सख्त स्ट्रक्चर्ड आउटपुट लौटाना
* अधिक जोखिम वाले निर्णय को मानव अनुमोदन के लिए रोकना
* मॉडल टर्न और टूल कॉल के बीच प्रगति का checkpoint बनाना

## 1. सीमित आउटपुट कॉन्ट्रैक्ट परिभाषित करें

```ts theme={null}
type CodeReviewPlan = {
  risk: "low" | "medium" | "high";
  summary: string;
  recommendedActions: string[];
  needsApproval: boolean;
};
```

इससे पहला कोड-रिव्यू workflow लॉग में जाँचना और बाद के worker चरणों तक भेजना आसान रहता है।

## 2. छोटे रनटाइम टूल परिभाषित करें

```ts theme={null}
import { defineTool } from "@phaseo/agent-sdk";

const lookupDiffSummary = defineTool({
  id: "lookup-diff-summary",
  description: "Return a short summary of the changed files in one pull request.",
  async execute(input: { pullRequestId: string }) {
    return {
      pullRequestId: input.pullRequestId,
      files: ["apps/api/src/pipeline/before/index.ts"],
      summary: "Changes touch request validation.",
    };
  },
});

const lookupFailingChecks = defineTool({
  id: "lookup-failing-checks",
  description: "Return the failing CI checks for one pull request.",
  async execute(input: { pullRequestId: string }) {
    return {
      pullRequestId: input.pullRequestId,
      failingChecks: ["web-typecheck"],
    };
  },
});
```

इन टूल को नियतात्मक और idempotent रखें, ताकि बाद में worker के फिर शुरू होने पर checkpoint किए गए स्टेप डेटा का उपयोग किया जा सके।

## 3. मानव समीक्षा के पड़ाव के साथ एजेंट बनाएँ

```ts theme={null}
import { createAgent } from "@phaseo/agent-sdk";

const codingReviewAgent = createAgent<string, CodeReviewPlan>({
  id: "coding-review-agent",
  model: "phaseo/free",
  instructions:
    "Use the available tools to inspect the coding task, then return a strict JSON review plan.",
  tools: [lookupDiffSummary, lookupFailingChecks],
  parseOutput(text) {
    return JSON.parse(text) as CodeReviewPlan;
  },
  humanReview: ({ parsedOutput }) =>
    parsedOutput?.needsApproval
      ? {
          reason: "coding_review_approval_required",
          payload: parsedOutput,
        }
      : null,
});
```

## 4. सख्त JSON के लिए gateway adapter इस्तेमाल करें

```ts theme={null}
import {
  createGatewayAgentClient,
} from "@phaseo/agent-sdk";

const client = createGatewayAgentClient({
  clientOptions: {
    apiKey: process.env.PHASEO_API_KEY!,
  },
  responseFormat: {
    type: "json_schema",
    name: "code_review_plan",
    schema: {
      type: "object",
      properties: {
        risk: {
          type: "string",
          enum: ["low", "medium", "high"],
        },
        summary: { type: "string" },
        recommendedActions: {
          type: "array",
          items: { type: "string" },
          minItems: 1,
        },
        needsApproval: { type: "boolean" },
      },
      required: ["risk", "summary", "recommendedActions", "needsApproval"],
      additionalProperties: false,
    },
  },
  plugins: [{ id: "response-healing", mode: "strict" }],
});
```

## 5. Workflow चलाएँ और फिर शुरू करें

```ts theme={null}
const result = await codingReviewAgent.run({
  input: "Review pull request pr_482 and produce a remediation plan.",
  client,
  onEvent(event) {
    console.log(event.type, event.runId);
  },
});

if (result.run.status === "waiting_for_human") {
  const continued = await codingReviewAgent.continueRun({
    run: result,
    client,
    humanInput: "Approved. Finalize the plan.",
  });

  console.log(continued.output);
}
```

## 6. क्या सत्यापित करें

टूल के साथ एक रन और अनुमोदन के लिए रुका हुआ एक रन चलाने के बाद, पुष्टि करें:

* अनुरोध विवरण में रनटाइम टूल लूप साफ़ दिखता है
* रुकी हुई रन की स्थिति `waiting_for_human` बन जाती है
* टूल निष्पादन के बाद स्टेप रिकॉर्ड checkpoint सेव करते हैं
* स्कीमा विफलताएँ या प्लगइन सुधार की गतिविधि लॉग में दिखती रहती है

## संबंधित गाइड

* [TypeScript Agent SDK](../sdk-reference/typescript/agent-sdk.mdx)
* [टिकाऊ एजेंट लूप बनाएँ](./agent-sdk-durable-loop.mdx)
* [स्ट्रक्चर्ड आउटपुट सत्यापित करें](../guides/structured-outputs.mdx)
* [गलत फ़ॉर्मैट वाले स्ट्रक्चर्ड JSON को रिकवर करें](./response-healing-for-structured-json.mdx)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.