agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Feature Request/Issue] Code execution and file I/O environment should be bound to a specific skill's directory

Open chcodex opened this issue 8 months ago • 21 comments

@fang-tech There's another issue: currently,

skillBox.codeExecution()
.workDir(workDir)
.withShell()
.withRead()
.withWrite()
.enable();

The workDir is independent of the directory of the specific uploaded skill, causing the model to frequently fail to find the actual path of the script when executing scripts within the skill. Is it possible to bind a specific workDir code execution and file read/write environment to a particular skill?

Originally posted by @Vinke2 in https://github.com/agentscope-ai/agentscope-java/issues/701#issuecomment-4059352631

chcodex avatar Mar 14 '26 03:03 chcodex

@fang-tech

chcodex avatar Mar 14 '26 03:03 chcodex

The contents of the "scripts" folder within the "resource" section of the "skill" should now be uninstalled and placed under the workDir/skills folder. You can check your path to see if any of the uninstalled files are present there.

fang-tech avatar Mar 14 '26 03:03 fang-tech

/tmp/8a9dfc6b78413ae62a1c68af79c0846a this workDir /tmp/8a9dfc6b78413ae62a1c68af79c0846a/skills/document_template_processing_classpath-skills this is Skills root Path

ShellCommandTool ,ReadFileTool,WriteFileTool There is no way to sense the skill root path, and after executing the cd, the next time the shell is executed, the working path will not be switched

@fang-tech

chcodex avatar Mar 14 '26 03:03 chcodex

The working directories of these three automatically registered tools will all be set as the working directory. In the skill prompt, they should use relative paths to read/write files or execute commands. In your case, their working directory is 8a9dfc6b78413ae62a1c68af79c0846a. You can execute them by using the command: ./skills/document_template_processing_classpath-skills/script.py

fang-tech avatar Mar 14 '26 03:03 fang-tech

@fang-tech document_template_processing_classpath-skills is automatically generated, so I cannot hardcode this path in my Skill.md.

chcodex avatar Mar 14 '26 04:03 chcodex

In your SKILL.md file, you should not use absolute paths. This will make it difficult to distribute and reuse your skills. It is a common practice to describe other resources within the skill using relative paths relative to your SKILL.md file.

fang-tech avatar Mar 14 '26 04:03 fang-tech

Plz modify the title of this issue so that the problem it mentions can be more easily retrieved.

fang-tech avatar Mar 14 '26 04:03 fang-tech

@fang-tech The workDir is /tmp/8a9dfc6b78413ae62a1c68af79c0846a. How can I use a relative path to access /tmp/8a9dfc6b78413ae62a1c68af79c0846a/skills/document_template_processing_classpath-skills? The key point is that document_template_processing_classpath-skills is not perceivable/identifiable.

chcodex avatar Mar 14 '26 04:03 chcodex

This temporary path was set as the working path for these three tools, meaning they naturally cd this folder.

fang-tech avatar Mar 14 '26 04:03 fang-tech

@fang-tech Each execution of ShellCommandTool is an independent process, and the cd state from the previous execution is not preserved for the next call. Even if the LLM actively uses cd to explore paths, it is useless, as relative paths cannot be used to execute scripts in subsequent calls.

chcodex avatar Mar 14 '26 04:03 chcodex

The "cd" here is merely an analogy. In reality, the "skill code execution" will set the baseDir for ShellCommandTool. Each newly created process will use this baseDir as its working space.

fang-tech avatar Mar 14 '26 04:03 fang-tech

I feel like we've come full circle. The baseDir and the skills root directory are different, and using relative paths won't work either because we don't know the actual path of the skill, which is document_template_processing_classpath-skills.

chcodex avatar Mar 14 '26 04:03 chcodex

The key point is that the actual skill root directory is not the same value as the skill defined in my SKILL.md.

chcodex avatar Mar 14 '26 04:03 chcodex

So you should modify your path in your SKILL.md to a relative path instead of an absolute path.

fang-tech avatar Mar 14 '26 04:03 fang-tech

You cannot write a relative path that you don't know, and this relative value cannot be known in advance. I feel like I'm going to be autistic

chcodex avatar Mar 14 '26 04:03 chcodex

Oh, I know what your questions are now, such as your skill is

/skills
  -/document-reader
     -/SKILL.md
     -/scripts/read.py

In fact, this directory structure will be saved. However, only a portion of the files will be unzipped to the workdir (by default, this includes the code files, scripts/, and assets/)

/workdir/skills
  -/document-reader
     -/scripts/read.py

fang-tech avatar Mar 14 '26 04:03 fang-tech

The key is that my skill directory was renamed after uploading, and my original skill directory was 'document_template_processing' and became 'document_template_processing_classpath-skills' after uploading

chcodex avatar Mar 14 '26 05:03 chcodex

The prompt of Skillbox states that the LLM should use the ID of the skill as the path. If you find that the final question is actually calling the original path, you can solve this problem by adjusting the prompt of Skillbox.

fang-tech avatar Mar 14 '26 05:03 fang-tech

SkillId is also dynamic and varies depending on how the skill is loaded

chcodex avatar Mar 14 '26 05:03 chcodex

SkillId is also dynamic and varies depending on how the skill is loaded

skill id will be passed as the part of skillbox prmopt

fang-tech avatar Mar 14 '26 05:03 fang-tech