mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Address comments
This commit is contained in:
@@ -6,4 +6,7 @@ protocols:
|
||||
version: 1.0.0
|
||||
resources:
|
||||
cpu: '0.25'
|
||||
memory: '0.5Gi'
|
||||
memory: '0.5Gi'
|
||||
environment_variables:
|
||||
- name: AZURE_AI_MODEL_DEPLOYMENT_NAME
|
||||
value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME}
|
||||
@@ -5,4 +5,7 @@ protocols:
|
||||
version: 1.0.0
|
||||
resources:
|
||||
cpu: "0.25"
|
||||
memory: 0.5Gi
|
||||
memory: 0.5Gi
|
||||
environment_variables:
|
||||
- name: AZURE_AI_MODEL_DEPLOYMENT_NAME
|
||||
value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME}
|
||||
@@ -7,5 +7,7 @@ resources:
|
||||
cpu: "0.25"
|
||||
memory: 0.5Gi
|
||||
environment_variables:
|
||||
- name: AZURE_AI_MODEL_DEPLOYMENT_NAME
|
||||
value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME}
|
||||
- name: GITHUB_PAT
|
||||
value: ${GITHUB_PAT}
|
||||
+6
-1
@@ -5,4 +5,9 @@ protocols:
|
||||
version: 1.0.0
|
||||
resources:
|
||||
cpu: "0.25"
|
||||
memory: 0.5Gi
|
||||
memory: 0.5Gi
|
||||
environment_variables:
|
||||
- name: AZURE_AI_MODEL_DEPLOYMENT_NAME
|
||||
value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME}
|
||||
- name: TOOLBOX_NAME
|
||||
value: "agent-tools"
|
||||
@@ -5,4 +5,7 @@ protocols:
|
||||
version: 1.0.0
|
||||
resources:
|
||||
cpu: "0.25"
|
||||
memory: 0.5Gi
|
||||
memory: 0.5Gi
|
||||
environment_variables:
|
||||
- name: AZURE_AI_MODEL_DEPLOYMENT_NAME
|
||||
value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME}
|
||||
@@ -16,12 +16,14 @@ The agent is hosted using the [Agent Framework](https://github.com/microsoft/age
|
||||
|
||||
### Tools
|
||||
|
||||
This agent uses two tools:
|
||||
This agent uses four tools:
|
||||
|
||||
1. **Local Shell Tool (`run_bash`)** – Executes shell commands locally to perform filesystem operations such as listing files, reading file contents, or creating directories. The tool captures stdout, stderr, and the exit code of the command and returns them as a string.
|
||||
2. **Code Interpreter Tool (`code_interpreter`)** – Allows the agent to execute Python code in a safe, sandboxed environment. This tool can be used to read and manipulate file contents, perform calculations, or run other Python logic as part of the agent's responses.
|
||||
1. **Get Current Working Directory Tool (`get_cwd`)** – Returns the current working directory of the agent host process.
|
||||
2. **List Files Tool (`list_files`)** – Lists the files in a specified directory.
|
||||
3. **Read File Tool (`read_file`)** – Reads the contents of a specified file.
|
||||
4. **Code Interpreter Tool (`code_interpreter`)** – Allows the agent to execute Python code in a safe.
|
||||
|
||||
> In this sample, the local shell tool is a function tool defined in Python using the `@tool` decorator from the Agent Framework. The code interpreter tool is a managed tool provided by [Foundry Toolbox](https://learn.microsoft.com/en-us/azure/foundry/agents/how-to/tools/toolbox). Learn more about foundry toolbox integration with hosted agents with this [sample](../04_foundry_toolbox/).
|
||||
> In this sample, the filesystem tools are function tools defined in Python using the `@tool` decorator from the Agent Framework. The code interpreter tool is a managed tool provided by [Foundry Toolbox](https://learn.microsoft.com/en-us/azure/foundry/agents/how-to/tools/toolbox). Learn more about foundry toolbox integration with hosted agents with this [sample](../04_foundry_toolbox/).
|
||||
|
||||
## Running the Agent Host
|
||||
|
||||
|
||||
@@ -6,4 +6,7 @@ protocols:
|
||||
version: 1.0.0
|
||||
resources:
|
||||
cpu: '0.25'
|
||||
memory: '0.5Gi'
|
||||
memory: '0.5Gi'
|
||||
environment_variables:
|
||||
- name: AZURE_AI_MODEL_DEPLOYMENT_NAME
|
||||
value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from agent_framework import Agent, tool
|
||||
from agent_framework.foundry import FoundryChatClient
|
||||
@@ -15,31 +14,32 @@ from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
|
||||
@tool(
|
||||
description="Execute a shell command for filesystem operations.",
|
||||
approval_mode="never_require",
|
||||
)
|
||||
def run_bash(command: str) -> str:
|
||||
"""Execute a shell command locally and return stdout, stderr, and exit code."""
|
||||
@tool(description="Get the current working directory.", approval_mode="never_require")
|
||||
def get_cwd() -> str:
|
||||
"""Get the current working directory."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
command,
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30,
|
||||
)
|
||||
parts: list[str] = []
|
||||
if result.stdout:
|
||||
parts.append(result.stdout)
|
||||
if result.stderr:
|
||||
parts.append(f"stderr: {result.stderr}")
|
||||
parts.append(f"exit_code: {result.returncode}")
|
||||
return "\n".join(parts)
|
||||
except subprocess.TimeoutExpired:
|
||||
return "Command timed out after 30 seconds"
|
||||
return os.getcwd()
|
||||
except Exception as e:
|
||||
return f"Error executing command: {e}"
|
||||
return f"Error getting current working directory: {e}"
|
||||
|
||||
|
||||
@tool(description="List files in a directory.", approval_mode="never_require")
|
||||
def list_files(directory: str) -> list[str]:
|
||||
"""List files in a directory."""
|
||||
try:
|
||||
return os.listdir(directory)
|
||||
except Exception as e:
|
||||
return [f"Error listing files in {directory}: {e}"]
|
||||
|
||||
|
||||
@tool(description="Read the contents of a file.", approval_mode="never_require")
|
||||
def read_file(file_path: str) -> str:
|
||||
"""Read the contents of a file."""
|
||||
try:
|
||||
with open(file_path) as f:
|
||||
return f.read()
|
||||
except Exception as e:
|
||||
return f"Error reading file {file_path}: {e}"
|
||||
|
||||
|
||||
async def main():
|
||||
@@ -68,7 +68,7 @@ async def main():
|
||||
"Make sure all mathematical calculations are performed using the code interpreter "
|
||||
"instead of mental arithmetic."
|
||||
),
|
||||
tools=[run_bash] + selected_tools,
|
||||
tools=[get_cwd, list_files, read_file] + selected_tools,
|
||||
# History will be managed by the hosting infrastructure, thus there
|
||||
# is no need to store history by the service. Learn more at:
|
||||
# https://developers.openai.com/api/reference/resources/responses/methods/create
|
||||
|
||||
Reference in New Issue
Block a user