Foundry 에이전트 서비스 코드 해석기(클래식)

참고

이 문서에서는 Microsoft Foundry(클래식) 에이전트를 참조합니다.

🔍 새 코드 인터프리터 설명서를 봅니다. 에이전트(클래식)는 이제 더 이상 사용되지 않으며 2027년 3월 31일에 사용 중지됩니다. 정식으로 출시된 Microsoft Foundry Agents Service에서 새로운 에이전트를 사용해 보십시오. 마이그레이션 가이드에 따라 워크로드를 업데이트합니다.

코드 인터프리터를 사용하면 에이전트가 샌드박스 실행 환경에서 Python 코드를 작성하고 실행할 수 있습니다. 코드 인터프리터를 사용하도록 설정하면 에이전트가 코드를 반복적으로 실행하여 더 까다로운 코드, 수학 및 데이터 분석 문제를 해결하거나 그래프 및 차트를 만들 수 있습니다. 에이전트가 실행되지 않는 코드를 작성하면 코드 실행이 성공할 때까지 다른 코드를 수정하고 실행하여 이 코드를 반복할 수 있습니다.

중요

코드 인터프리터에는 Azure OpenAI 사용량에 대한 토큰 기반 요금 외에도 추가 요금이 있습니다. 에이전트가 서로 다른 두 스레드에서 동시에 코드 인터프리터를 호출하는 경우 두 개의 코드 인터프리터 세션이 만들어집니다. 각 세션은 기본적으로 1시간 동안 활성화되며 유휴 시간 제한은 30분입니다.

필수 구성 요소

코드 샘플

코드 인터프리터를 사용하여 에이전트 만들기

code_interpreter = CodeInterpreterTool()

# An agent is created with the Code Interpreter capabilities:
agent = project_client.agents.create_agent(
    model=os.environ["MODEL_DEPLOYMENT_NAME"],
    name="my-agent",
    instructions="You are helpful agent",
    tools=code_interpreter.definitions,
    tool_resources=code_interpreter.resources,
)

사용할 코드 인터프리터용 파일 첨부

파일이 코드 인터프리터와 함께 사용되도록 하려면 이 함수를 upload_and_poll 사용할 수 있습니다.

file = agents_client.files.upload_and_poll(file_path=asset_file_path, purpose=FilePurpose.AGENTS)
print(f"Uploaded file, file ID: {file.id}")

code_interpreter = CodeInterpreterTool(file_ids=[file.id])

코드 인터프리터를 사용하여 에이전트 만들기

var projectEndpoint = System.Environment.GetEnvironmentVariable("ProjectEndpoint");
var modelDeploymentName = System.Environment.GetEnvironmentVariable("ModelDeploymentName");

PersistentAgentsClient client = new(projectEndpoint, new DefaultAzureCredential());

PersistentAgent agent = client.Administration.CreateAgent(
    model: modelDeploymentName,
    name: "My Friendly Test Agent",
    instructions: "You politely help with math questions. Use the code interpreter tool when asked to visualize numbers.",
    tools: [new CodeInterpreterToolDefinition()]
);

사용할 코드 인터프리터용 파일 첨부

코드 인터프리터와 함께 파일을 사용하려는 경우 메시지에 첨부할 수 있습니다.

PersistentAgentFileInfo uploadedAgentFile = client.Files.UploadFile(
    filePath: "sample_file_for_upload.txt",
    purpose: PersistentAgentFilePurpose.Agents);
var fileId = uploadedAgentFile.Id;

var attachment = new MessageAttachment(
    fileId: fileId,
    tools: tools
);

// attach the file to the message
PersistentThreadMessage message = client.Messages.CreateMessage(
    threadId: thread.Id,
    role: MessageRole.User,
    content: "Can you give me the documented information in this file?",
    attachments: [attachment]
);

코드 인터프리터를 사용하여 에이전트 만들기

// Create the code interpreter tool
const codeInterpreterTool = ToolUtility.createCodeInterpreterTool();

// Enable the code interpreter tool during agent creation
const agent = await client.createAgent("gpt-4o", {
  name: "my-agent",
  instructions: "You are a helpful agent",
  tools: [codeInterpreterTool.definition],
  toolResources: codeInterpreterTool.resources,
});
console.log(`Created agent, agent ID: ${agent.id}`);

사용할 코드 인터프리터용 파일 첨부

코드 인터프리터와 함께 파일을 사용하려는 경우 도구에 첨부할 수 있습니다.

// Upload file and wait for it to be processed
const filePath = "./examplefile.csv";
const localFileStream = fs.createReadStream(filePath);
const localFile = await client.files.upload(localFileStream, "assistants", {
  fileName: "localFile",
});
// Create code interpreter tool
const codeInterpreterTool = ToolUtility.createCodeInterpreterTool([localFile.id]);

코드 인터프리터 도구를 사용하여 에이전트 만들기

curl --request POST \
  --url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/assistants?api-version=$API_VERSION \
  -H "Authorization: Bearer $AGENT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "instructions": "You are an AI assistant that can write code to help answer math questions.",
    "tools": [
      { "type": "code_interpreter" }
    ],
    "model": "gpt-4o-mini",
    "tool_resources"{
      "code interpreter": {
      }
    }
  }'
String agentName = "code_interpreter_agent";
CodeInterpreterToolDefinition ciTool = new CodeInterpreterToolDefinition();
CreateAgentOptions createAgentOptions = new CreateAgentOptions(modelName).setName(agentName).setInstructions("You are a helpful agent").setTools(Arrays.asList(ciTool));
PersistentAgent agent = administrationClient.createAgent(createAgentOptions);

사용할 코드 인터프리터용 파일 첨부

코드 인터프리터와 함께 파일을 사용하려는 경우 도구에 첨부할 수 있습니다.

FileInfo uploadedFile = filesClient.uploadFile(new UploadFileRequest(
    new FileDetails(BinaryData.fromFile(htmlFile))
    .setFilename("sample.html"), FilePurpose.AGENTS));

MessageAttachment messageAttachment = new MessageAttachment(Arrays.asList(BinaryData.fromObject(ciTool))).setFileId(uploadedFile.getId());

PersistentAgentThread thread = threadsClient.createThread();
ThreadMessage createdMessage = messagesClient.createMessage(
    thread.getId(),
    MessageRole.USER,
    "What does the attachment say?",
    Arrays.asList(messageAttachment),
    null);

지원되는 모델

모델 페이지에는 에이전트와 코드 인터프리터가 지원되는 지역/모델에 관한 가장 최신 정보가 포함되어 있습니다.

최신 모델을 사용하는 에이전트를 활용하여 새로운 기능, 더 큰 컨텍스트 창, 최신 학습 데이터를 최대한 활용할 것을 권장합니다.

지원되는 파일 형식

파일 형식 MIME 형식
.c text/x-c
.cpp text/x-c++
.csv application/csv
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.html text/html
.java text/x-java
.json application/json
.md text/markdown
.pdf application/pdf
.php text/x-php
.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
.py text/x-python
.py text/x-script.python
.rb text/x-ruby
.tex text/x-tex
.txt text/plain
.css text/css
.jpeg image/jpeg
.jpg image/jpeg
.js text/javascript
.gif image/gif
.png image/png
.tar application/x-tar
.ts application/typescript
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xml application/xml 또는 text/xml
.zip application/zip