@phaseo/agent-sdk उपयोग करें:
- कई चरणों वाले tool loops
- local runtime tools
- SDK द्वारा लौटाए गए state से resumable runs
- स्पष्ट human approval pauses
- typed final outputs
- मौजूदा TypeScript SDK के ज़रिए Gateway मॉडल टर्न
स्थिति मॉडल
Agent SDK runs को किसी भी Phaseo-hosted service में persist नहीं करता।run()बाद में जारी रखने के लिए आवश्यक पूरा state लौटाता है।- यदि application को requests के बीच या process restart के बाद run फिर से शुरू करना हो, तो लौटाया गया state अपने application store में persist करें।
continueRun()उस पिछले run state को सीधे स्वीकार करता है।
इंस्टॉल करें
SDK में शामिल सुविधाएँ
createAgent()defineTool()createGatewayAgentClient()- पहले लौटाए गए run state से जारी रखने के लिए
continueRun() - incremental और replayable results के लिए
stream()औरcontinueStream() stepCountIs(),maxCost()औरhasToolCall()जैसे stop-condition helpers
पहला agent
मानसिक मॉडल
runtime loop चार काम करता है:- मौजूदा message state को model client को भेजता है
- लौटाए गए local tool calls को चलाता है
- tool results को अगले turn में जोड़ता है
- हर step boundary पूरा होने पर updated run state लौटाता है
मुख्य primitives
createAgent()
createAgent() से ये परिभाषित करें:
- एक स्थिर
id - instructions
- एक model या preset
- tools की एक छोटी सूची
- वैकल्पिक output parsing
- वैकल्पिक human review नियम
- वैकल्पिक retry और tool-execution controls
defineTool()
स्थानीय runtime tools को इनसे परिभाषित करें:
iddescription- वैकल्पिक JSON
parameters - वैकल्पिक
timeoutMs inputSchemaऔरoutputSchemaruntime validatorsexecute(),execute: falseया मानवीय समीक्षा के कॉलबैकrequireApproval,onError,nextTurnParamsऔर progress events
context.signal abort करता है, run को failed mark करता है और timeout error फिर से throw करता है।
Schemas function या parse()/safeParse() देने वाले किसी भी object के रूप में हो सकते हैं। गलत model arguments और tool results, tool boundary पार करने से पहले fail होते हैं।
अनुमोदन, HITL और मैन्युअल टूल
side effects वाले tool को हर call पर gate करें:run.pause.pendingToolCalls पर pause होता है। concurrent calls को अलग पहचानने के लिए exact call ID से resume करें:
execute: false रखें और उसका परिणाम toolOutputs से दें। Interactive tool के लिए onToolCalled से null लौटाएँ; जारी रखने के बाद onResponseReceived मानव response को validate या transform कर सकता है।
प्रगति देने वाले tools
एक async generator शुरुआती नतीजे प्रकाशित करके एक अंतिम परिणाम लौटा सकता है:tool.preliminary_result events और step के preliminaryResults में दिखता है।
स्ट्रीमिंग परिणाम
stream() streaming model client के साथ वही state machine शुरू करता है। इसके consumers को replay किया जा सकता है, इसलिए UI, telemetry और persistence code एक साथ पढ़ सकते हैं:
getReasoningStream(), getItemsStream(), getToolStream() या getFullStream() उपयोग करें। cancel() run को abort करता है।
टाइप किए गए रन आइटम रेंडर करें
getItemsStream() AgentItem<TOutput> देता है, एक discriminated union जिसे switch में सुरक्षित रूप से उपयोग किया जा सकता है:
run() या stream() के बाद वही क्रमबद्ध आइटम अनुबंध completed.items में मिलता है। प्रदाता का आउटपुट संदेश, तर्क-विचार, टूल-कॉल, टूल-परिणाम, त्रुटि और अंतिम-आउटपुट आइटम में सामान्यीकृत होता है। सामान्यीकृत प्रदाता आइटम के प्रदाता-विशिष्ट फ़ील्ड rawProviderItem से मिलते हैं।
रोकने की शर्तें और डायनामिक टर्न
Stop conditions array के रूप में जुड़ती हैं; पहली matching condition कारण दर्ज करती है औरstopped run लौटाती है:
context.setContext() से application context सेट कर सकते हैं और तुरंत अगले turn को nextTurnParams से override कर सकते हैं।
createGatewayAgentClient()
जब model turns को Phaseo Gateway के ज़रिए चलना चाहिए, तब gateway-backed adapter उपयोग करें।
यह gateway-native controls जैसे इन विकल्पों को ले जा सकता है:
responseFormatpluginsgatewayToolstoolChoicewebSearchOptionsproviderOptionspromptCacheKeyincludeMeta
एप्लिकेशन द्वारा प्रबंधित स्थायित्व
अगर application को resumability चाहिए, तो लौटाया गयाAgentRunResult सीधे persist करें या asynchronous load(runId) और save(result) methods वाला state accessor दें। फिर जारी run हर layer से serialized record गुज़ारे बिना runId उपयोग कर सकता है।
SDK जानबूझकर persistence adapters या hosted state backend शामिल नहीं करता।
इसका मतलब है कि आप:
- one-shot runs को पूरी तरह process में रखना
- paused या incomplete runs को अपने application records में serialize करना
- बाद में saved run state फिर लोड करके
continueRun()को देना
मानवीय समीक्षा और आगे जारी रखना
जब run को checkpoint बनाकर approval की प्रतीक्षा करनी हो, तबhumanReview उपयोग करें:
प्रकारित आउटपुट
जब app को typed final value चाहिए, तबparseOutput उपयोग करें:
रनटाइम नियंत्रण
मॉडल पुनः प्रयास
जब अस्थायी model failures पर run कोfailed persist करने से पहले retry करना हो, तब modelRetry उपयोग करें:
maxRetries में गिने जाते हैं।
Persist किए गए step record में अंतिम retry count modelAttempts के रूप में रखा जाता है।
समवर्ती स्थानीय टूल
एक model turn कई independent tools को सुरक्षित रूप से call कर सकता हो तोtoolExecution.toolConcurrency सेट करें:
प्रीसेट-आधारित रूटिंग
routing, prompt या parameter defaults को app code में hard-code करने के बजाय dashboard में manage करना हो तोpreset उपयोग करें:
इवेंट हुक
logs, telemetry या internal workflows के lifecycle hooks चाहिए हों तोonEvent उपयोग करें।
मौजूदा events में शामिल हैं:
run.startedrun.resumedstep.startedstep.completedstep.failedstep.cancelledmodel.requestedmodel.completedmodel.failedtool.startedtool.completedtool.failedcheckpoint.savedrun.waiting_for_humanrun.cancelledrun.completedrun.failed
step.completed emit करता है।
त्रुटि प्रबंधन
Gateway failures कोAgentGatewayError के रूप में फिर throw किया जाता है:
errorDetails भी persist होता है।
शामिल उदाहरण
पैकेज में अभी ये उदाहरण शामिल हैं:examples/research-brief-agent.tsexamples/support-triage-agent.tsexamples/coding-review-agent.tsexamples/parallel-tool-agent.ts
मौजूदा दायरा
SDK जानबूझकर application-building primitives पर केंद्रित है:- स्थानीय या ऐप-प्रबंधित चेकपॉइंट सहेजना
- Gateway के ज़रिए मॉडल टर्न
- स्थानीय टूल
- फिर से शुरू किए जा सकने वाले एजेंट लूप
- हर चरण का सामान्यीकृत टोकन उपयोग, लागत, चेतावनियाँ, समाप्ति कारण और टूल परिणाम