24 배치된 에이전트 호출
운용 응용 프로그램에서 에이전트의 끝점 URL을 호출할 수 있습니다.
에이전트 엔드포인트를 호출하는 데 사용되는 프로그래밍 인터페이스에 관계없이 OCI를 통해 인증되고 관련 권한이 있어야 합니다. 에이전트 끝점의 경우 호출자는 에이전트 끝점에 대해 최소한 USE 권한을 가져야 합니다.
끝점 URI는 에이전트 UI의 세부정보 탭에 문서화되어 있습니다. 해당 끝점 URI를 코드에 복사하여 에이전트를 호출할 수 있습니다.

배치된 에이전트를 워크플로우 작업의 일부로 호출하려면 에이전트 작업 생성을 참조하십시오.
끝점 URI를 호출하는 메소드
다양한 도구, SDK 및 CLI를 통해 에이전트 끝점 URI를 호출할 수 있습니다.
다음 메소드를 사용하면 Oracle AI Data Platform 에이전트에서 끝점 URI를 호출할 수 있습니다.
OCI CLI로 호출
oci raw-request
--http-method POST
--target-uri <your-agent-flow-endpoint-uri>
--request-body '{"query":"Tell me about the Ryder Cup in 1985"}'
--auth <security_token>Python 요청 라이브러리로 호출
import oci import requests import json import uuid from contextlib import closing from requests import Request, Response
class AuthHelper: """ AuthHelper allows creating an OCI signer with either API key or security_token (which are short term sessions) """ def init(self, oci_profile: str, use_security_token:bool = True): config = oci.config.from_file(file_location="/Volumes/jr/default/misc/config",profile_name=oci_profile) if use_security_token: with open(config["security_token_file"], 'r') as f: token = f.read() private_key = oci.signer.load_private_key_from_file(config["key_file"])
self.signer = oci.auth.signers.SecurityTokenSigner(token, private_key) else: self.signer = oci.signer.Signer( tenancy=config["tenancy"], user=config["user"], fingerprint=config["fingerprint"], private_key_file_location=config["key_file"], #pass_phrase=config.get("pass_phrase"), #private_key_content=config.get("key_content") )
@property
def Signer(self):
return self.signer
class MyRawJsonRpcClient: """ Simple class using requests lib to post JSON to chat endpoint using OCI signing """ def init(self, chat_url:str, oci_profile: str, sessionKey:str, use_security_token:bool = True): self.authhelper = AuthHelper(oci_profile=oci_profile, use_security_token=use_security_token) self.authsigner = self.authhelper.Signer self.chat_url = chat_url self.sessionKey = sessionKey
def send(self, input:str) -> Response:
body = {
"isStreamEnabled" : False,
"sessionKey" : self.sessionKey,
"trace" : False,
"input" :[{
"role":"User",
"content":[{
"type" : "INPUT_TEXT",
"text" : input
}]
}]
}
response:Request = requests.post(
url =self.chat_url,
params = None,
auth = self.authsigner,
json=body,
headers={}
)
return response
sessionKey을 제공할 수 있습니다. sessionKey은 에이전트와 사용자 세션의 고유 식별자입니다. 동일한 sessionKey를 계속 재사용하는 경우 사용자 메시지와 에이전트 응답이 동일한 보존에 추가됩니다. client = MyRawJsonRpcClient(chat_url="<your-agent-flow-endpoint-uri>",
oci_profile = "DEFAULT",
sessionKey= “<your-session-key>”,
use_security_token = False )사용자 메시지를 제공하고 클라이언트를 사용하여 에이전트 끝점 URI로 메시지를 보낼 수도 있습니다. user_input = f"Hello, tell me a good dad joke."
r = client.send(input = user_input)
response_json = r.json()APEX 사용
AI Data Platform Samples Github 저장소에서 사용 가능한 코드 샘플을 사용할 수 있습니다. 이 샘플은 APEX 애플리케이션에서 에이전트 배치 끝점을 호출하는 프로세스를 안내합니다.
Streamlit을 통해
AI Data Platform Samples Github 저장소에서 사용 가능한 코드 샘플을 사용할 수 있습니다. 샘플은 Streamlit 애플리케이션에서 에이전트 배치 끝점을 호출하는 프로세스를 안내합니다.
모범 사례 - 비동기 및 비동기 응답
비동기 응답을 가정하는 클라이언트 코드를 작성하는 것이 좋습니다. 예:
import httpx
async def fetch_data():
async with httpx.AsyncClient() as client:
response = await client.get(URL)
return response.json()