-
Notifications
You must be signed in to change notification settings - Fork 105
feat(generator): add AI-powered skill generator with multi-provider support #177
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
Open
charantejguniganti
wants to merge
8
commits into
PSMRI:main
Choose a base branch
from
charantejguniganti:feat/ai-skill-generator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b163619
feat(mcp): add retry and failure recovery for agent task execution
charantejguniganti a499355
chore(mcp): add package.json, tsconfig.json, and .gitignore for amrit…
charantejguniganti 5a23acf
fix: update retry config and clean up code
charantejguniganti 80b5b30
feat: implement AI-powered skill generator and example skills
charantejguniganti 5f0ae0a
feat(generator): add interactive mode, regeneration, diagram export, …
charantejguniganti 3835aff
docs(PR): update PR description structure with concrete metrics
charantejguniganti ba14ed8
feat(generator): add Ollama support and multi-stage skill generation
charantejguniganti 2f1304e
fix: rethrow non-404 errors during README branch probing
charantejguniganti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules/ | ||
| dist/ |
169 changes: 169 additions & 0 deletions
169
docs/ai-framework/mcp-servers/amrit-docs-mcp/RETRY_DESIGN.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| # Agent Task Retry & Failure Recovery | ||
|
|
||
| > **Scope:** `docs/ai-framework/mcp-servers/amrit-docs-mcp/` | ||
| > **Affects:** Network-bound MCP tool helpers (`fetchGitHubReadme`, `fetchRepoStructure`) | ||
| > **Breaking changes:** None — all existing tool APIs are identical. | ||
|
|
||
| --- | ||
|
|
||
| ## Why this is needed | ||
|
|
||
| The MCP server makes live HTTP calls to GitHub (raw content + GitHub API) for | ||
| every `get_repo_readme` and `get_repo_structure` tool call. Without retry logic, | ||
| a single transient network blip returns an error to the AI agent — even though | ||
| resending the same request milliseconds later would succeed. | ||
|
|
||
| For a health-data platform like AMRIT where agents may run in constrained | ||
| network environments (rural deployments, CI pipelines), silent retries give | ||
| reliability without changing the agent's experience. | ||
|
|
||
| --- | ||
|
|
||
| ## Architecture | ||
|
|
||
| ``` | ||
| MCP Tool Handler | ||
| │ | ||
| ▼ | ||
| fetchGitHubReadme / fetchRepoStructure | ||
| │ | ||
| ▼ | ||
| withRetry(taskName, task, config) ◄── new | ||
| │ | ||
| ├── attempt 1 ──► axios.get(url, { timeout: 5000 }) | ||
| │ ↓ fails | ||
| ├── backoff (300ms × 2^1 + jitter) | ||
| ├── attempt 2 ──► axios.get(url, { timeout: 5000 }) | ||
| │ ↓ fails | ||
| ├── backoff (300ms × 2^2 + jitter) | ||
| ├── attempt 3 ──► axios.get(url, { timeout: 5000 }) | ||
| │ ↓ fails | ||
| └── throw last error ──► MCP tool returns graceful error message | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Execution States | ||
|
|
||
| | State | Description | | ||
| |-------|-------------| | ||
| | `Pending` | Task created, not yet started | | ||
| | `Running` | First attempt in progress | | ||
| | `Retrying` | Subsequent attempt after a recoverable failure | | ||
| | `Success` | Task completed successfully | | ||
| | `Failed` | All attempts exhausted or non-retryable error encountered | | ||
|
|
||
| --- | ||
|
|
||
| ## Configuration (`RetryConfig`) | ||
|
|
||
| | Field | Type | Default | Description | | ||
| |-------|------|---------|-------------| | ||
| | `maxRetries` | `number` | `3` | Retry attempts after first failure | | ||
| | `baseDelayMs` | `number` | `300` | Base for exponential backoff (ms) | | ||
| | `maxDelayMs` | `number` | `10000` | Cap on any single backoff delay (ms) | | ||
| | `jitter` | `boolean` | `true` | Add randomness to avoid retry storms | | ||
| | `isRetryable` | `fn` | always true | Filter which errors trigger a retry | | ||
|
|
||
| **Backoff formula:** | ||
| ``` | ||
| delay = min(baseDelayMs × 2^attempt, maxDelayMs) + (jitter ? random(0, baseDelayMs) : 0) | ||
| ``` | ||
|
|
||
| | Attempt | Delay (no jitter) | | ||
| |---------|-------------------| | ||
| | 1st retry | 600ms | | ||
| | 2nd retry | 1,200ms | | ||
| | 3rd retry | 2,400ms | | ||
| | 4th retry | 4,800ms | | ||
|
|
||
| --- | ||
|
|
||
| ## Files Changed | ||
|
|
||
| | File | Change | | ||
| |------|--------| | ||
| | `src/retry.ts` | **New** — self-contained retry engine, `withRetry()`, `isNetworkError()` | | ||
| | `src/retry.test.ts` | **New** — 13 unit tests covering all states and edge cases | | ||
| | `src/index.ts` | **Modified** — imports retry module, wraps `fetchGitHubReadme` and `fetchRepoStructure`, version bumped `1.0.0` → `1.1.0` | | ||
|
Comment on lines
+87
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test count in docs is stale versus the current suite. The doc says 13 tests, but Also applies to: 168-168 🤖 Prompt for AI Agents |
||
|
|
||
| --- | ||
|
|
||
| ## Edge Cases Handled | ||
|
|
||
| | Scenario | Behaviour | | ||
| |----------|-----------| | ||
| | **Network timeout** (`ECONNABORTED`) | Retried up to `maxRetries` times with backoff | | ||
| | **HTTP 5xx** | Retried — server-side transient failure | | ||
| | **HTTP 4xx** (404, 400) | Fails fast — `isNetworkError` returns `false` | | ||
| | **Invalid task input** | Custom `isRetryable` predicate can short-circuit retries | | ||
| | **Repeated failures** | All failure reasons logged with timestamps and attempt numbers | | ||
| | **Partial success** | Each branch URL tried independently; success on any branch returns immediately | | ||
| | **Max retries reached** | Last error re-thrown; full failure log emitted to stderr | | ||
|
|
||
| --- | ||
|
|
||
| ## Usage Examples | ||
|
|
||
| ### Basic usage | ||
| ```ts | ||
| import { withRetry } from "./retry.js"; | ||
|
|
||
| const data = await withRetry( | ||
| "fetch-readme:HWC-API", | ||
| () => axios.get(url, { timeout: 5000 }).then(r => r.data), | ||
| { maxRetries: 3, baseDelayMs: 300, maxDelayMs: 8000, jitter: true } | ||
| ); | ||
| ``` | ||
|
|
||
| ### With retryable predicate | ||
| ```ts | ||
| import { withRetry, isNetworkError } from "./retry.js"; | ||
|
|
||
| // Will retry on 5xx and timeouts, but NOT on 404 | ||
| const data = await withRetry("my-task", task, { | ||
| maxRetries: 3, | ||
| isRetryable: isNetworkError, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Custom predicate | ||
| ```ts | ||
| await withRetry("validate-task", task, { | ||
| maxRetries: 2, | ||
| isRetryable: (err) => { | ||
| if (err instanceof Error && err.message.startsWith("Invalid")) return false; | ||
| return true; | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Running Tests | ||
|
|
||
| ```bash | ||
| cd docs/ai-framework/mcp-servers/amrit-docs-mcp | ||
| npx ts-node --esm src/retry.test.ts | ||
| ``` | ||
|
|
||
| Expected output: | ||
| ``` | ||
| running retry engine tests… | ||
|
|
||
| ✅ succeeds on first attempt | ||
| ✅ succeeds on second attempt after one failure | ||
| ✅ throws after exhausting all retries | ||
| ✅ non-retryable 404 fails fast without retrying | ||
| ✅ retryable 500 error triggers retry | ||
| ✅ network timeout error is retried | ||
| ✅ works with async task function | ||
| ✅ partial success: fails twice then succeeds | ||
| ✅ invalid task input throws without retrying | ||
| ✅ isNetworkError returns true for timeout code | ||
| ✅ isNetworkError returns false for 404 | ||
| ✅ isNetworkError returns true for 500 | ||
| ✅ DEFAULT_RETRY_CONFIG has expected values | ||
|
|
||
| 13 tests: 13 passed, 0 failed. | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add language identifiers to fenced code blocks.
These fences are unlabeled and currently trigger MD040 lint warnings.
💡 Proposed fix
Also applies to: 69-69, 151-151
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 24-24: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents