Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor agent_fs to defAgent and update related documentation #755

Merged
merged 7 commits into from
Oct 4, 2024

Conversation

pelikhan
Copy link
Member

@pelikhan pelikhan commented Oct 4, 2024

This pull request refactors the existing agent_fs functionality into a new defAgent declaration, enhancing the structure and clarity of the code. It includes updates to the related documentation and types, ensuring that the new agent can be effectively utilized within the system. The changes aim to improve maintainability and usability for future development.


  • The agent_fs tool seems to be replaced by a new interface fs. This is a significant change that would impact existing consumers. 🔄
  • This change is seen in the system.mdx and system.agent_fs.genai.mjs files, where the agent_fs definitions are replaced by fs.
  • The new fs tool appears to be more intuitive, with an apparent simplification of parameters and a potentially more straight-forward usage. 🧰
  • Notably, a number of helper functions have been migrated from "system" to directly under "tools". ⚙️
  • In the runpromptcontext.ts, a new function defAgent is introduced. This function looks to facilitate the declaration of an LLM agent, including function handling and the definition of tools and systems. 🆕
  • Changes in packages/core/src/prompt_template.d.ts and packages/core/src/prompt_type.ts indicate this new defAgent function is added to the public API, hence being user facing. 🙋‍♂️
  • Also noteworthy is a new interface DefAgentOptions added to the public API, which appears to extend PromptGeneratorOptions.
  • Overall, this commit seems to be designed to make it easier to define a language model agent with various tools and handle its operations more efficiently. 👌

Please note that actual impact would depend on projects using these features. Be sure to carefully test all functionalities after this update! 🧪

generated by pr-describe

@@ -6,7 +6,6 @@ import { LinkCard } from '@astrojs/starlight/components';

### Builtin tools

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link to the agent_fs documentation has been removed, which may lead to a broken link or missing information for users.

generated by pr-docs-review-commit broken_link

@@ -102,7 +102,7 @@ Agent that can find, search or read files to accomplish tasks



Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description for the agent_fs tool has been removed, which may leave users without necessary context or information about the tool's purpose.

generated by pr-docs-review-commit missing_content

"fs_diff_files",
"retrieval_fuzz_search",
"md_frontmatter",
],
}
)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The detailed documentation and example usage for the agent_fs tool have been replaced with a less informative defAgent call, reducing the amount of information available to the user.

generated by pr-docs-review-commit missing_content

Copy link

github-actions bot commented Oct 4, 2024

The modifications in this pull request introduce a new concept, an "agent". It appears that these agents are a type of tool in the system that can be defined in a similar way to other tools, but they have some unique characteristics.

Changes include:

  • A new function defAgent is added in runpromptcontext.ts, which looks like it allows defining an agent with a specific name, description, function, and options. This function seems to create a tool with certain settings and functionalities.
  • In prompt_template.d.ts and prompt_type.d.ts, new types and interfaces are introduced to support the new agent concept such as DefAgentOptions, ChatAgentHandler, and the method defAgent.
  • The import statement in runpromptcontext.ts has been updated to import the uniq function from 'es-toolkit'.

Concerns

  • There are no obvious functional issues in the changes. However, it's hard to understand the exact role and usage of these agents without further context or documentation. It would be beneficial if more comments or some form of documentation was provided to explain the new "agent" concept, especially in how it differs from regular tools.

Overall, the code changes seem to be well-structured and consistent.
The codebase would benefit from additional comments explaining the newly introduced concepts.

Here is a possible enhancement:

@@ -280,6 +280,10 @@ export function createChatGenerationContext(
                 )
         }
     }
+    // Defines a new type of tool called "agent"
+    // An agent is a tool that uses LLM to perform certain tasks
+    // This function is used to define an agent with specified name, description, function, and options
+    // The options can include system, tools, and other parameters
     const defAgent = (
         name: string,
         description: string,

LGTM 🚀

generated by pr-review

<LinkCard title="agent_git" description="Agent that can query a repository using Git to accomplish tasks. Provide all the context information available to execute git queries." href="/genaiscript/reference/scripts/system#systemagent_git" />
<LinkCard title="agent_github" description="Agent that can query GitHub to accomplish tasks" href="/genaiscript/reference/scripts/system#systemagent_github" />
<LinkCard title="agent_interpreter" description="Run code interpreters for Python, Math. Use this agent to ground computation questions." href="/genaiscript/reference/scripts/system#systemagent_interpreter" />
<LinkCard title="agent_user_input" description="Ask user for input to confirm, select or answer a question." href="/genaiscript/reference/scripts/system#systemagent_user_input" />
<LinkCard title="fs_diff_files" description="Computes a diff between two files." href="/genaiscript/reference/scripts/system#systemfs_diff_files" />
<LinkCard title="fs_find_files" description="Finds file matching a glob pattern. Use pattern to specify a regular expression to search for in the file content." href="/genaiscript/reference/scripts/system#systemfs_find_files" />
<LinkCard title="fs_read_file" description="Reads a file as text from the file system. Returns undefined if the file does not exist." href="/genaiscript/reference/scripts/system#systemfs_read_file" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'agent_fs', 'agent_git', 'agent_github', 'agent_interpreter', and 'agent_user_input' LinkCards have been removed. Ensure that this change is intentional and that any references to these agents are updated accordingly in the documentation.

generated by pr-docs-review-commit documentation_update

"fs_diff_files",
"retrieval_fuzz_search",
"md_frontmatter",
],
}
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'agent_fs' tool has been refactored to 'defAgent' with a simplified interface. Verify that the documentation reflects the correct usage and that examples are updated to match the new interface.

generated by pr-docs-review-commit documentation_update

return res
}
`Your are a helpfull LLM agent that can use git tools to query a repository. `,
{ model, tools: ["git"] }
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'agent_git' tool has been refactored to 'defAgent' with a simplified interface. Verify that the documentation reflects the correct usage and that examples are updated to match the new interface.

generated by pr-docs-review-commit documentation_update

"system.github_files",
"system.github_issues",
"system.github_pulls",
],
}
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'agent_github' tool has been refactored to 'defAgent' with a simplified interface. Verify that the documentation reflects the correct usage and that examples are updated to match the new interface.

generated by pr-docs-review-commit documentation_update

"system.explanations",
"system.math",
"system.python_code_interpreter",
],
}
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'agent_interpreter' tool has been refactored to 'defAgent' with a simplified interface. Verify that the documentation reflects the correct usage and that examples are updated to match the new interface.

generated by pr-docs-review-commit documentation_update

)
return res
model,
system: ["system", "system.tools", "system.user_input"],
}
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'agent_user_input' tool has been refactored to 'defAgent' with a simplified interface. Verify that the documentation reflects the correct usage and that examples are updated to match the new interface.

generated by pr-docs-review-commit documentation_update

<LinkCard title="agent_git" description="Agent that can query a repository using Git to accomplish tasks. Provide all the context information available to execute git queries." href="/genaiscript/reference/scripts/system#systemagent_git" />
<LinkCard title="agent_github" description="Agent that can query GitHub to accomplish tasks" href="/genaiscript/reference/scripts/system#systemagent_github" />
<LinkCard title="agent_interpreter" description="Run code interpreters for Python, Math. Use this agent to ground computation questions." href="/genaiscript/reference/scripts/system#systemagent_interpreter" />
<LinkCard title="agent_user_input" description="Ask user for input to confirm, select or answer a question." href="/genaiscript/reference/scripts/system#systemagent_user_input" />
<LinkCard title="fs_diff_files" description="Computes a diff between two files." href="/genaiscript/reference/scripts/system#systemfs_diff_files" />
<LinkCard title="fs_find_files" description="Finds file matching a glob pattern. Use pattern to specify a regular expression to search for in the file content." href="/genaiscript/reference/scripts/system#systemfs_find_files" />
<LinkCard title="fs_read_file" description="Reads a file as text from the file system. Returns undefined if the file does not exist." href="/genaiscript/reference/scripts/system#systemfs_read_file" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of several LinkCard components may indicate that the corresponding agents are deprecated or moved. Ensure that this change is intentional and that any references to these agents are updated or removed elsewhere in the documentation to maintain consistency.

generated by pr-docs-review-commit documentation_content

"fs_diff_files",
"retrieval_fuzz_search",
"md_frontmatter",
],
}
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The agent_fs tool has been refactored to defAgent. Ensure that the documentation reflects the new usage and that examples or references to the old agent_fs are updated accordingly.

generated by pr-docs-review-commit documentation_content

id: kind === "Agent" ? "agent_" + id : id,
description,
kind: kind.toLocaleLowerCase(),
})
return ""
}
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regular expression used in parsePromptScriptTools function does not account for case sensitivity in the kind group. This could lead to incorrect tool identification if the kind is not in the exact case as expected. Consider using case-insensitive matching.

generated by pr-review-commit regex_handling

return res
}
`Your are a helpfull LLM agent that can use git tools to query a repository. `,
{ model, system: ["system.github_info"], tools: ["git"] }
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The agent_git tool has been refactored to defAgent. Ensure that the documentation reflects the new usage and that examples or references to the old agent_git are updated accordingly.

generated by pr-docs-review-commit documentation_content

}

type ChatAgentHandler = (ctx: ChatGenerationContext, args: ChatFunctionArgs) => Awaitable<unknown>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DefAgentOptions interface is defined but not used anywhere in the code. This could lead to confusion for other developers. Consider removing it if it's not needed, or use it where it's supposed to be used.

generated by pr-review-commit unused_type

"system.github_files",
"system.github_issues",
"system.github_pulls",
],
}
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The agent_github tool has been refactored to defAgent. Ensure that the documentation reflects the new usage and that examples or references to the old agent_github are updated accordingly.

generated by pr-docs-review-commit documentation_content

"system.explanations",
"system.math",
"system.python_code_interpreter",
],
}
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The agent_interpreter tool has been refactored to defAgent. Ensure that the documentation reflects the new usage and that examples or references to the old agent_interpreter are updated accordingly.

generated by pr-docs-review-commit documentation_content

)
return res
model,
system: ["system", "system.tools", "system.user_input"],
}
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The agent_user_input tool has been refactored to defAgent. Ensure that the documentation reflects the new usage and that examples or references to the old agent_user_input are updated accordingly.

generated by pr-docs-review-commit documentation_content

`
const { auth, owner, repo, baseUrl } = info
$`- current github repository: ${owner}/${repo}`
if (baseUrl) $`- current github base url: ${baseUrl}`
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitHub information section has been simplified. Verify that the new format provides all necessary information and is consistent with the rest of the documentation.

generated by pr-docs-review-commit documentation_content

defTool(
"agent_github",
defAgent(
"github",
"Agent that can query GitHub to accomplish tasks",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description for the github agent has been simplified and made more concise.

generated by pr-docs-review-commit documentation_update

defTool(
"agent_interpreter",
defAgent(
"interpreter",
"Run code interpreters for Python, Math. Use this agent to ground computation questions.",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description for the interpreter agent has been simplified and made more concise.

generated by pr-docs-review-commit documentation_update

defTool(
"agent_user_input",
defAgent(
"user_input",
"Ask user for input to confirm, select or answer a question.",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description for the user_input agent has been simplified and made more concise.

generated by pr-docs-review-commit documentation_update

@@ -888,7 +752,7 @@ defTool("git_branch_list", "List all branches using git.", {}, async () => {

defTool(
"git_diff",
"Computes file diffs using git. If the diff is too large, it returns the list of modified/added files.",
"Computes file diffs using the git diff command. If the diff is too large, it returns the list of modified/added files.",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description for git_diff has been updated to clarify the use of the git diff command.

generated by pr-docs-review-commit documentation_update

"git_log",
"Generates a log of commits using git.",
"git_list_commits",
"Generates a history of commits using the git log command.",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The git_log tool has been renamed to git_list_commits and the description updated to reflect the use of the git log command.

generated by pr-docs-review-commit documentation_update

`
const { auth, owner, repo, baseUrl } = info
$`- current github repository: ${owner}/${repo}`
if (baseUrl) $`- current github base url: ${baseUrl}`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitHub information output format has been changed to a more concise bullet list format.

generated by pr-docs-review-commit documentation_update

<LinkCard title="agent_git" description="Agent that can query a repository using Git to accomplish tasks. Provide all the context information available to execute git queries." href="/genaiscript/reference/scripts/system#systemagent_git" />
<LinkCard title="agent_github" description="Agent that can query GitHub to accomplish tasks" href="/genaiscript/reference/scripts/system#systemagent_github" />
<LinkCard title="agent_interpreter" description="Run code interpreters for Python, Math. Use this agent to ground computation questions." href="/genaiscript/reference/scripts/system#systemagent_interpreter" />
<LinkCard title="agent_user_input" description="Ask user for input to confirm, select or answer a question." href="/genaiscript/reference/scripts/system#systemagent_user_input" />
<LinkCard title="fs_diff_files" description="Computes a diff between two files." href="/genaiscript/reference/scripts/system#systemfs_diff_files" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here.

generated by pr-docs-review-commit typo

Register JavaScript functions as [LLM tools](/genaiscript/reference/scripts/tools/)

```js wrap
defTool("weather", "live weahter",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here.

generated by pr-docs-review-commit typo

defAgent(
"fs",
"Queries files to accomplish tasks",
"Your are a helpfull LLM agent that can query the file system to accomplish tasks.",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here.

generated by pr-docs-review-commit typo

)
return res
}
`Your are a helpfull LLM agent that can use the git tools to query the current repository. The current repository is the same as github repository.`,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here.

generated by pr-docs-review-commit typo

"Agent that can query GitHub to accomplish tasks",
`Your are a helpfull LLM agent that can query GitHub to accomplish tasks.
Prefer diffing job logs rather downloading entire logs which can be very large.`,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here.

generated by pr-docs-review-commit typo

"Run code interpreters for Python, Math. Use this agent to ground computation questions.",
`You are an agent that can run code interpreters for Python, Math.
- Prefer math_eval for math expressions as it is much more efficient.
- To use file data in python, prefer copying data files using python_code_interpreter_copy_files rather than inline data in code.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here.

generated by pr-docs-review-commit typo

"Ask user for input to confirm, select or answer a question.",
`You are an agent that can ask questions to the user and receive answers. Use the tools to interact with the user.
- the message should be very clear. Add context from the conversation as needed.`,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here.

generated by pr-docs-review-commit typo

@@ -1027,9 +892,9 @@ defTool(
defTool(
"github_actions_runs_list",
`List all runs for a workflow or the entire repository.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here.

generated by pr-docs-review-commit typo

Copy link

github-actions bot commented Oct 4, 2024

Investigator report

Summary of the Root Cause

The failure in the GitHub Action is due to TypeScript errors in the src/testhost.ts file. Specifically, the TestHost class is incorrectly implementing the RuntimeHost interface because it is missing the project property, which is required by the RuntimeHost interface.

Code Responsible for the Failure

The error messages in the logs are:

src/testhost.ts:52:14 - error TS2420: Class 'TestHost' incorrectly implements interface 'RuntimeHost'.
  Property 'project' is missing in type 'TestHost' but required in type 'RuntimeHost'.

52 export class TestHost implements RuntimeHost {
                ~~~~~~~~

And

src/testhost.ts:78:24 - error TS2345: Argument of type 'TestHost' is not assignable to parameter of type 'RuntimeHost'.
  Property 'project' is missing in type 'TestHost' but required in type 'RuntimeHost'.

78         setRuntimeHost(new TestHost())
                          ~~~~~~~~~~~~~~

Suggested Fix

To fix these errors, the TestHost class should implement the project property as required by the RuntimeHost interface.

Suggested Code Diff

--- a/src/testhost.ts
+++ b/src/testhost.ts
@@ -51,6 +51,8 @@
 
 export class TestHost implements RuntimeHost {
 
+    project: Project;
+
     constructor() {
         // Initialize other properties
+        this.project = /* initialization */;
     }
 }

This change includes the missing project property in the TestHost class and initializes it accordingly. Adjust the initialization based on the actual requirements of your application.

generated by gai

Copy link

github-actions bot commented Oct 4, 2024

It seems I encountered some issues accessing the specific data needed. Here's how you can proceed to investigate the workflow failure:

  1. Check Workflow Status:

    • Go to the GitHub Actions page for the defagent branch.
    • Locate the run with ID 66543451 to view its status and logs for any error messages.
  2. Identify Root Cause:

    • Review the logs to identify where the failure occurred. It often provides hints like a failing test, a broken dependency, or a configuration issue.
  3. Correlate with Commits, PRs, or Issues:

    • Check recent commits, pull requests, or issues that might be related to changes in the defagent branch around the time of the failed run.
  4. Compare Source Code:

    • Identify the commit hash of the failed run and the last successful run.
    • Use the GitHub comparison feature (e.g., https://github.com/microsoft/genaiscript/compare/{last_successful_commit}...{failed_commit}) to compare changes in the source code between these two runs.

These steps should help you pinpoint the cause of the failure and find related changes or issues.

generated by github-agent

Copy link

github-actions bot commented Oct 4, 2024

Workflow Failure Analysis

Latest Failed Run

  • Run ID: 11183617169
  • Conclusion: Failure
  • Commit SHA: 96c751669a9bc52d09d49c05e10e770ab0931bae

Last Successful Run

  • Run ID: 11182445678
  • Conclusion: Success
  • Commit SHA: bd1738aaf6f7830b25ada179928d677c11972739

Jobs Comparison

Both runs had similar job structures with completed statuses. Detailed job logs might reveal specific errors, but we need to examine the source code and commits to understand the failures.

Code Changes & Commits

No specific commit log or file diff was retrieved. It might be necessary to inspect commits between the successful and failed SHA manually to pinpoint changes.

Issues & Correlations

No direct correlation with specific open issues or pull requests was found. Here's a list of open issues that may be relevant:

  • Issue #755: Refactor agent_fs to defAgent and update related documentation
  • Issue #744: Cleanup stats vs usage

These issues could potentially relate to the workflow's failure, especially if recent code changes addressed these topics.

Next Steps

  • Investigate specific error messages from the job logs for run 11183617169.
  • Review the code changes between commits bd1738aaf6f7830b25ada179928d677c11972739 and 96c751669a9bc52d09d49c05e10e770ab0931bae.
  • Cross-reference any recently merged pull requests that could affect the workflow on the defagent branch.

Feel free to ask for more detailed inspection or specific job log retrieval!

generated by github-one


```js wrap
defAgent(
"git",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here.

generated by pr-docs-review-commit typo

throw new Error(`tool ${toolName} not found`)
throw new Error(
`multi tool ${toolName} not found in ${tools.map((t) => t.spec.name).join(", ")}`
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message thrown when a tool is not found could potentially leak sensitive information about the available tools in the system. Consider revising the error message to avoid exposing too much information.

generated by pr-review-commit error_handling

@@ -996,22 +860,23 @@ defTool("git_last_tag", "Gets the last tag using git.", {}, async () => {

github workflows

Queries results from workflows in GitHub actions.
Queries results from workflows in GitHub actions. Prefer using dffs to compare logs.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here.

generated by pr-docs-review-commit typo

@@ -242,18 +242,18 @@ export async function expandTemplate(

if (status !== "success" || text === "")
// cancelled
return Object.freeze({
return {
status,
statusText,
messages,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of Object.freeze has been removed which could potentially lead to mutation of the returned objects. If immutability is a requirement, consider reintroducing Object.freeze.

generated by pr-review-commit object_freeze

@@ -1127,7 +992,7 @@ defTool(

defTool(
"github_actions_job_logs_diff",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here.

generated by pr-docs-review-commit typo

)
return res
}
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defAgent function is quite complex and long. Consider breaking it down into smaller, more manageable functions to improve readability and maintainability.

generated by pr-review-commit complex_function

@pelikhan pelikhan merged commit f41ffa0 into main Oct 4, 2024
8 checks passed
@pelikhan pelikhan deleted the defagent branch October 4, 2024 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant