> ## 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.

> ## Agent Instructions
> Phaseo Gateway base URL: https://api.phaseo.app/v1. Send `Authorization: Bearer $PHASEO_API_KEY` with every request.
> Model IDs look like `provider/model`, for example `openai/gpt-6-astra`. Do not guess IDs: list them with `GET /v1/models` or check https://phaseo.app/models. `phaseo/free` routes to an available free model and needs no wallet balance.
> For new text integrations prefer `POST /v1/responses`. `POST /v1/chat/completions` (OpenAI format) and `POST /v1/messages` (Anthropic format) suit existing code.
> The full API contract is https://phaseo.app/docs/openapi/v1/openapi.yaml. Official SDKs: `@phaseo/sdk` (TypeScript) and `phaseo` (Python), plus Go, C#, PHP, Ruby and Rust.
> Search these docs over MCP at https://phaseo.app/docs/mcp, and install Phaseo skills with `npx skills add https://phaseo.app/docs`. If a page is wrong or out of date, report it with the MCP `submit_feedback` tool.
> Manage Phaseo accounts with the `phaseo` CLI (`npm install -g @phaseo/cli`, then `phaseo login` or `phaseo login --device-code`), the `/v1` Management API or the MCP server at `https://mcp.phaseo.app/mcp?access=manage`. Do not send users to the dashboard for account tasks. A person is still needed for sign-up, approving a sign-in, paying the first top-up on the checkout link that `phaseo credits add` returns when no card is saved, confirming each saved-card top-up from the emailed link, and account security (password, MFA, passkeys). Create API keys with `phaseo keys create --name <name> --json`; never guess one. Credit top-ups need `phaseo login --scopes billing:write` first. Task map: https://phaseo.app/docs/v1/developers/manage-from-an-agent.md.

# Agent SDK गतिशील टर्न

> एजेंट को फिर से बनाए बिना टर्न के बीच उसका मॉडल, निर्देश, sampling या टूल बदलें।

जब किसी बाद वाले मॉडल टर्न को ऐप्लिकेशन संदर्भ या पिछले नतीजों पर निर्भर होना हो, तब तय मान की जगह एक function दें। रनटाइम हर मॉडल अनुरोध से पहले इसे टर्न संख्या, स्टेप इंडेक्स, मैसेज और संदर्भ के साथ कॉल करता है। Rust में प्रति-टर्न callbacks नहीं हैं; यह [मॉडल प्रति रन सेट करता है](#set-the-model-per-run-in-rust)।

## हर टर्न में सेटिंग बदलें

```typescript TypeScript theme={null}
type ResearchContext = {
  fast: boolean;
};

const agent = createAgent<string, string, ResearchContext>({
  id: "research-agent",
  model: ({ context }) =>
    context?.fast ? "openai/gpt-6-astra" : "openai/gpt-6-astra-pro",
  instructions: ({ numberOfTurns }) =>
    `Research turn ${numberOfTurns}. Cite the evidence you use.`,
});
```

```python Python theme={null}
agent = create_agent({
    "id": "research-agent",
    "model": lambda turn: "openai/gpt-6-astra" if (turn["context"] or {}).get("fast") else "openai/gpt-6-astra-pro",
    "instructions": lambda turn: f"Research turn {turn['number_of_turns']}. Cite the evidence you use.",
})
```

```go Go theme={null}
agent := phaseoagent.CreateAgent(phaseoagent.AgentDefinition{
  ID:    "support-agent",
  Model: "openai/gpt-6-astra",
  DynamicModel: func(turn phaseoagent.TurnContext) string {
    if turn.StepIndex >= 3 {
      return "openai/gpt-6-astra-pro"
    }
    return "openai/gpt-6-astra"
  },
  DynamicInstructions: func(turn phaseoagent.TurnContext) string {
    return fmt.Sprintf("Resolve the request. Current context: %v", turn.Context)
  },
})
```

```csharp C# theme={null}
var agent = AgentSdk.CreateAgent(new AgentDefinition
{
    Id = "support-agent",
    Model = "openai/gpt-6-astra",
    DynamicModel = turn => turn.StepIndex >= 3 ? "openai/gpt-6-astra-pro" : "openai/gpt-6-astra",
    DynamicInstructions = turn => $"Resolve the request. Current context: {turn.Context}",
});
```

```php PHP theme={null}
$agent = AgentSdk::createAgent(new AgentDefinition(
    id: "support-agent",
    model: fn (array $turn) => $turn["step_index"] >= 3
        ? "openai/gpt-6-astra-pro"
        : "openai/gpt-6-astra",
    instructions: fn (array $turn) => "Resolve the request. Current context: " . json_encode($turn["context"]),
));
```

```ruby Ruby theme={null}
agent = PhaseoAgentSdk.create_agent(
  id: "support-agent",
  model: ->(turn) {
    turn[:step_index] >= 3 ? "openai/gpt-6-astra-pro" : "openai/gpt-6-astra"
  },
  instructions: ->(turn) {
    "Resolve the request. Current context: #{turn[:context].inspect}"
  }
)
```

```java Java theme={null}
// Callbacks 19-argument constructor के आख़िरी छह arguments हैं।
var agent = AgentSdk.createAgent(new AgentSdk.AgentDefinition(
    "support-agent", "openai/gpt-6-astra", null, "Resolve the request.",
    List.of(), 12, null, null, null, null,
    List.of(), null, null,                         // stopWhen, outputSchema, requireApproval
    turn -> turn.stepIndex() >= 3 ? "openai/gpt-6-astra-pro" : "openai/gpt-6-astra", // dynamicModel
    turn -> "Resolve the request. Current context: " + turn.context(),         // dynamicInstructions
    null, null, null,                              // temperature, maxOutputTokens, topP
    null                                           // dynamicTools
));
```

### आप हर टर्न में क्या बदल सकते हैं

| सेटिंग | TypeScript | Python | Go | C# | PHP | Ruby | Java |
| - | - | - | - | - | - | - | - |
| मॉडल | `model` | `model` | `DynamicModel` | `DynamicModel` | `model` | `model:` | `dynamicModel` |
| निर्देश | `instructions` | `instructions` | `DynamicInstructions` | `DynamicInstructions` | `instructions` | `instructions:` | `dynamicInstructions` |
| Temperature | `temperature` | `temperature` | `Temperature` (`*float64`) | `Temperature` (`double?`) | `temperature` | `temperature:` | `temperature` (`Double`) |
| Top-p | `topP` | `top_p` | `TopP` (`*float64`) | `TopP` (`double?`) | `topP` | `top_p:` | `topP` (`Double`) |
| अधिकतम आउटपुट टोकन | `maxOutputTokens` | `max_output_tokens` | `MaxOutputTokens` (`*int`) | `MaxOutputTokens` (`int?`) | `maxOutputTokens` | `max_output_tokens:` | `maxOutputTokens` (`Integer`) |
| दिए गए टूल | `activeTools` (टूल ID) | प्रति टर्न नहीं; `next_turn_params` का उपयोग करें | `DynamicTools` (`[]Tool`) | `DynamicTools` (`IReadOnlyList<Tool>`) | `dynamicTools` | `dynamic_tools:` | `dynamicTools` (`List<Tool>`) |
| मॉडल सूची | `models` | नहीं | नहीं | नहीं | नहीं | नहीं | नहीं |

TypeScript, Python, PHP और Ruby तय फ़ील्ड की जगह एक function लेते हैं। Go, C# और Java तय `Model` और `Instructions` के बगल में अलग callback फ़ील्ड का उपयोग करते हैं। TypeScript में, `activeTools` से बाहर छोड़े गए टूल कॉल किए जा सकते रहते हैं, ताकि पिछली कॉल फिर भी resolve हो सकें।

टर्न argument में हर भाषा में वही चार मान होते हैं:

| भाषा | टर्न argument |
| - | - |
| TypeScript | `numberOfTurns`, `stepIndex`, `messages`, `context` वाला object |
| Python | `number_of_turns`, `step_index`, `messages`, `context` वाली dict |
| Go, C# | `NumberOfTurns`, `StepIndex`, `Messages`, `Context` वाला `TurnContext` |
| PHP | `number_of_turns`, `step_index`, `messages`, `context` वाला array |
| Ruby | `:number_of_turns`, `:step_index`, `:messages`, `:context` वाला hash |
| Java | `numberOfTurns()`, `stepIndex()`, `messages()`, `context()` वाला `TurnContext` |

Python में, `run()` को दिया गया `model` या `preset` हर टर्न के लिए definition के मॉडल की जगह ले लेता है।

## किसी टूल से ऐप्लिकेशन संदर्भ अपडेट करें

कोई टूल उस ऐप्लिकेशन संदर्भ को बदल सकता है जिसे बाद के टर्न पढ़ते हैं: TypeScript में `context.setContext()`, Python में `runtime.set_context()`, और [टूल](https://phaseo.app/docs/hi/v1/sdk-reference/agent/tools.md#report-progress-and-update-context) में दिए गए समकक्ष। जब आप रन सहेजते हैं और बाद में उन्हें जारी रखते हैं, तो संदर्भ छोटा और serializable रखें।

```typescript theme={null}
const chooseMode = defineTool({
  id: "choose-mode",
  async execute(input: { fast: boolean }, context) {
    context.setContext({ fast: input.fast });
    return { selected: input.fast ? "fast" : "thorough" };
  },
});
```

## सिर्फ़ अगला टर्न override करें

एजेंट definition बदले बिना, किसी टूल के ठीक बाद आने वाले अनुरोध को बदलने के लिए उस टूल पर next-turn पैरामीटर सेट करें। उस एक टर्न के लिए ये प्रति-टर्न functions से ऊपर रहते हैं।

```typescript TypeScript theme={null}
const broadenSearch = defineTool({
  id: "broaden-search",
  nextTurnParams: {
    model: "openai/gpt-6-astra-pro",
    maxOutputTokens: 2_000,
  },
  async execute() {
    return { broadened: true };
  },
});
```

```python Python theme={null}
broaden_search = define_tool(AgentTool(
    id="broaden-search",
    next_turn_params={"model": "openai/gpt-6-astra-pro", "max_output_tokens": 2_000},
    execute=lambda tool_input, runtime: {"broadened": True},
))
```

```go Go theme={null}
inspect := phaseoagent.Tool{
  ID:       "inspect_repository",
  Execute:  inspectRepository,
  NextTurn: &phaseoagent.NextTurnParams{Model: "openai/gpt-6-astra-pro"},
}
```

```csharp C# theme={null}
var inspect = new Tool("inspect_repository", InspectRepository)
{
    NextTurnParams = new NextTurnParams(Model: "openai/gpt-6-astra-pro"),
};
```

```php PHP theme={null}
$inspect = new Tool(
    id: "inspect_repository",
    execute: fn (array $input, $runtime) => inspectRepository($input),
    nextTurnParams: ["model" => "openai/gpt-6-astra-pro"],
);
```

```ruby Ruby theme={null}
inspect_repo = PhaseoAgentSdk::Tool.new(
  id: "inspect_repository",
  execute: ->(input, runtime) { inspect_repository(input) },
  next_turn_params: { model: "openai/gpt-6-astra-pro" }
)
```

```java Java theme={null}
// इसे टूल के आख़िरी constructor argument के रूप में दें।
new AgentSdk.NextTurnParams("openai/gpt-6-astra-pro", null, null, null, null, null)
```

Next-turn पैरामीटर मॉडल, निर्देश, temperature, top-p, अधिकतम आउटपुट टोकन और टूल स्वीकार करते हैं, जिनके नाम हर भाषा की casing में होते हैं। Python में टर्न के बीच टूल सूची बदलने का यही एकमात्र तरीका है।

अगर टूल अनुमोदन का इंतज़ार करता है, तो उसके overrides रुके हुए रन के साथ सहेजे जाते हैं और जारी रखने के बाद वाले टर्न पर लागू होते हैं:

| भाषा | कहाँ सहेजे जाते हैं |
| - | - |
| TypeScript | जारी रखने पर जब अनुमोदित कॉल चलती है, तब लागू होते हैं |
| Python | `run.next_turn_params` |
| Go | `Run.NextTurn` |
| C# | `Run.NextTurn` |
| PHP | `$result->run->nextTurnParams` |
| Ruby | `result.run.next_turn_params` |
| Java | `run().nextTurn()` |

जिस नीति को आप हर टर्न में फिर से गणना करवाना चाहते हैं उसके लिए प्रति-टर्न functions का उपयोग करें, और किसी ख़ास टूल से एक बार के handoff के लिए next-turn पैरामीटर का।

## Rust में मॉडल प्रति रन सेट करें

Rust के `phaseo-agent` 0.2 में प्रति-टर्न callbacks, टूल से संदर्भ अपडेट या next-turn पैरामीटर नहीं हैं। `RunOptions` के साथ मॉडल, स्टेप सीमा और ऐप्लिकेशन संदर्भ प्रति रन सेट करें:

```rust theme={null}
let mut options = RunOptions::new("Explain when to use routing presets.");
options.model = Some("openai/gpt-6-astra-pro".to_string());
options.max_steps = Some(4);
options.context = serde_json::json!({ "workspace": "docs" });

let result = agent.run(&mut client, options)?;
```


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