Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/tiny-agents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Or using a local or remote endpoint URL:

Where `servers` is a list of MCP servers (we support Stdio, SSE, and HTTP servers).

Optionally, you can add a `PROMPT.md` file to override the default Agent prompt.
Optionally, you can add an [`AGENTS.md`](https://agents.md/) (or `PROMPT.md`) file to override the default Agent prompt.

Then just point tiny-agents to your local folder:

Expand All @@ -93,7 +93,7 @@ npx @huggingface/tiny-agents run "julien-c/flux-schnell-generator"
```

> [!NOTE]
> Want to share your own agent with the community? Submit a PR to the [Tiny Agents](https://huggingface.co/datasets/tiny-agents/tiny-agents/discussions) repository on the Hub. Your submission must include an `agent.json` file, and you can optionally add a `PROMPT.md` file. To help others understand your agent's capabilities, consider including an `EXAMPLES.md` file with sample prompts and use cases.
> Want to share your own agent with the community? Submit a PR to the [Tiny Agents](https://huggingface.co/datasets/tiny-agents/tiny-agents/discussions) repository on the Hub. Your submission must include an `agent.json` file, and you can optionally add a `PROMPT.md` or [`AGENTS.md`](https://agents.md/) file. To help others understand your agent's capabilities, consider including an `EXAMPLES.md` file with sample prompts and use cases.

## Advanced: Programmatic Usage

Expand Down
44 changes: 30 additions & 14 deletions packages/tiny-agents/src/lib/loadConfigFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { TinyAgentConfig } from "./types";
import { debug, error } from "./utils";

const FILENAME_CONFIG = "agent.json";
const FILENAME_PROMPT = "PROMPT.md";
const PROMPT_FILENAMES = ["AGENTS.md", "PROMPT.md"] as const;

const TINY_AGENTS_HUB_REPO: RepoDesignation = {
name: "tiny-agents/tiny-agents",
Expand All @@ -29,10 +29,18 @@ async function tryLoadFromDirectory(dirPath: string): Promise<TinyAgentConfig |
}

let prompt: string | undefined;
try {
prompt = await readFile(join(dirPath, FILENAME_PROMPT), { encoding: "utf8" });
} catch {
debug(`PROMPT.md not found in ${dirPath}, continuing without prompt template`);
for (const filename of PROMPT_FILENAMES) {
try {
prompt = await readFile(join(dirPath, filename), { encoding: "utf8" });
break;
} catch {
/* empty */
}
}
if (undefined == prompt) {
debug(
`${PROMPT_FILENAMES.join(", ")} could not be loaded locally from ${dirPath}, continuing without prompt template`
);
}

try {
Expand Down Expand Up @@ -60,16 +68,24 @@ async function tryLoadFromHub(agentId: string): Promise<TinyAgentConfig | undefi
}

let prompt: string | undefined;
try {
const promptPath = await downloadFileToCacheDir({
repo: TINY_AGENTS_HUB_REPO,
path: `${agentId}/${FILENAME_PROMPT}`,
accessToken: process.env.HF_TOKEN,
});
prompt = await readFile(promptPath, { encoding: "utf8" });
} catch {
for (const filename of PROMPT_FILENAMES) {
try {
const promptPath = await downloadFileToCacheDir({
repo: TINY_AGENTS_HUB_REPO,
path: `${agentId}/${filename}`,
accessToken: process.env.HF_TOKEN,
});
prompt = await readFile(promptPath, { encoding: "utf8" });
break;
} catch {
/* empty */
}
}
if (undefined == prompt) {
debug(
`PROMPT.md not found in https://huggingface.co/datasets/tiny-agents/tiny-agents/tree/main/${agentId}, continuing without prompt template`
`${PROMPT_FILENAMES.join(
", "
)} not found in https://huggingface.co/datasets/tiny-agents/tiny-agents/tree/main/${agentId}, continuing without prompt template`
);
}

Expand Down