|
| 1 | +# DHTI elixir coding agent |
| 2 | + |
| 3 | +Elixirs provide backend GenAI capabilities as HTTP endpoints hosted by LangServe. You are a elixir coding agent working in a fresh development environment. Follow these instructions **strictly and sequentially**. |
| 4 | + |
| 5 | +## Environment setup and project scaffolding |
| 6 | + |
| 7 | +* Install \`uv\` in the dev environment\*\* (if not already installed). |
| 8 | +* In the project root, run: |
| 9 | + |
| 10 | +```bash |
| 11 | + |
| 12 | +uvx cookiecutter https://github.com/dermatologist/cookiecutter-uv.git |
| 13 | + |
| 14 | +``` |
| 15 | + |
| 16 | +- When cookiecutter prompts you: |
| 17 | + - **author**: Set to the provided author name (or use a reasonable placeholder if none is given). |
| 18 | + - **email**: Set to the provided email (or use a reasonable placeholder if none is given). |
| 19 | + - **author_github_handle**: Set to the provided GitHub handle (or a reasonable placeholder if none is given). |
| 20 | + - **project_name**: Generate a concise, meaningful project name that reflects the requested features for this Elixir agent. THE NAME MUST START WITH "dhti-elixir-". |
| 21 | + - **project_slug**: Generate a clean, snake_case slug derived from the project name. THE SLUG MUST START WITH "dhti_elixir_". |
| 22 | + - **project_description**: Generate a detailed project description clearly summarizing: |
| 23 | + - the purpose of the project, |
| 24 | + - the kind of Elixir-related functionality requested, |
| 25 | + - the intended clinical / FHIR context (if implied by the request below). |
| 26 | +- **Cookiecutter options:** |
| 27 | + - Keep **all cookiecutter options at their default values**, **except**: |
| 28 | + - For select dhti: |
| 29 | + - Set this to 2-y (yes). |
| 30 | + - For open_source_license: |
| 31 | + - If an open source license is **explicitly** mentioned in the request, choose the corresponding option. |
| 32 | + - Otherwise, select **option 7: "Not open source"**. |
| 33 | + |
| 34 | +## Study the reference implementation |
| 35 | + |
| 36 | +Before editing any generated files, **carefully read and understand** the following reference files, paying attention to patterns, structure, and responsibilities: |
| 37 | + |
| 38 | +- **Chain implementation:** |
| 39 | + - chain.py reference: |
| 40 | + - <https://github.com/dermatologist/dhti-elixir-template/blob/feature/agent-2/src/dhti_elixir_template/chain.py> |
| 41 | +- **Bootstrap / configuration of the chain:** |
| 42 | + - bootstrap.py reference: |
| 43 | + - <https://github.com/dermatologist/dhti-elixir-template/blob/feature/agent-2/src/dhti_elixir_template/bootstrap.py> |
| 44 | + |
| 45 | +Extract and internalize the following from these references: |
| 46 | + |
| 47 | +- How the LangChain chain is constructed (inputs, outputs, prompts, tools, callbacks, etc.). |
| 48 | +- How configuration, environment variables, and settings are wired in bootstrap.py. |
| 49 | +- How FHIR or other external services are integrated, if present. |
| 50 | +- Any conventions for logging, error handling, and dependency injection. |
| 51 | + |
| 52 | +You must follow the **same architectural and stylistic patterns** in the new project's chain.py and bootstrap.py. |
| 53 | + |
| 54 | +## Implement the new Elixir request |
| 55 | + |
| 56 | +Your primary task is to **update the newly created chain.py and bootstrap.py** in the generated project to implement the following specification: |
| 57 | + |
| 58 | +<new elixir request here> |
| 59 | + |
| 60 | +Interpret this as the high-level functional requirement for the chain. Your implementation should: |
| 61 | + |
| 62 | +- **Align with the reference pattern:** |
| 63 | + - Mirror the structure, abstractions, and flow used in the reference chain.py and bootstrap.py. |
| 64 | + - Reuse naming conventions, configuration style, and initialization patterns where appropriate. |
| 65 | +- **FHIR-based data retrieval:** |
| 66 | + - Retrieve any required data using **FHIR search**. |
| 67 | + - Read and carefully study FHIR search here: <https://r.jina.ai/https://www.hl7.org/fhir/search.html> |
| 68 | + - Read how fhir search is implemented in dhti-elixir-base here: <https://github.com/dermatologist/dhti-elixir-base/tree/develop/src/dhti_elixir_base/fhir>. This is available as a dependency in the generated project. Hence you can use fhir search functionality from dhti-elixir-base in your implementation and avoid code duplication. |
| 69 | + - Use appropriate FHIR resource types and query parameters based on the needs implied by the <new elixir request here> specification. |
| 70 | + - Implement FHIR interactions in a way that is: |
| 71 | + - Configurable (e.g., via environment variables or settings), |
| 72 | + - Robust (handles typical error conditions), |
| 73 | + - Consistent with the reference template's practices (if defined there). |
| 74 | +- **Dependencies and package usage:** |
| 75 | + - Prefer existing dependencies and standard library where possible. |
| 76 | + - Only introduce **additional Python packages** when clearly necessary. |
| 77 | + - If you add any new package: |
| 78 | + - Add it to pyproject.toml as a dependency in the appropriate section. |
| 79 | + - Ensure compatibility with the existing project structure (e.g., version constraints if needed). |
| 80 | +- **Chain behavior:** |
| 81 | + - Define the chain's inputs, outputs, and key steps clearly. |
| 82 | + - Ensure the chain logic fulfills all aspects of <new elixir request here>, including: |
| 83 | + - Any domain logic surrounding Elixir code analysis, generation, or orchestration. |
| 84 | + - Any interactions with external services (e.g., FHIR, LLMs, tools) as appropriate. |
| 85 | + |
| 86 | +## 4\. Planning: create a TODO list |
| 87 | + |
| 88 | +Before writing or heavily modifying code, create an **elaborate, structured TODO list** in a notes/todo.md file. This TODO list should: |
| 89 | + |
| 90 | +- Break the work into small, concrete tasks. |
| 91 | +- Cover: |
| 92 | + - **Environment & setup** (if anything beyond cookiecutter defaults is needed), |
| 93 | + - **Chain design** (inputs/outputs, internal steps, FHIR interactions), |
| 94 | + - **Implementation tasks** for chain.py and bootstrap.py, |
| 95 | + - **Dependency updates** (if new packages are needed), |
| 96 | + - **Unit testing** tasks, |
| 97 | + - **Documentation updates** (README), |
| 98 | + - **Validation and final checks**. |
| 99 | + |
| 100 | +Use clear, actionable items that you can check off logically as you progress. |
| 101 | + |
| 102 | +## Implementation details |
| 103 | + |
| 104 | +- **Update chain.py:** |
| 105 | + - Implement the chain logic following the patterns from the reference chain.py. |
| 106 | + - Integrate FHIR search where needed. |
| 107 | + - Ensure the chain is testable, modular, and readable. |
| 108 | + - Include inline comments where non-trivial logic is implemented. |
| 109 | +- **Update bootstrap.py:** |
| 110 | + - Configure the chain, environment variables, and external services following the patterns of the reference bootstrap.py. |
| 111 | + - Ensure: |
| 112 | + - FHIR endpoint configuration is clearly defined (and overridable), |
| 113 | + - Logging and error handling are consistent with the reference style, |
| 114 | + - Any secrets or sensitive settings are expected via environment variables or configuration files, not hard-coded. |
| 115 | +- **Dependency management:** |
| 116 | + - If you added new packages: |
| 117 | + - Confirm they are correctly listed in pyproject.toml. |
| 118 | + - Ensure any import paths are correct and code runs without import errors. |
| 119 | + |
| 120 | +## Testing |
| 121 | + |
| 122 | +- **Write unit tests** for the new behavior: |
| 123 | + - Place tests in the appropriate test directory or module, consistent with the generated project's testing structure. |
| 124 | + - Cover: |
| 125 | + - Core chain behavior (including expected inputs/outputs), |
| 126 | + - FHIR search integration (using mocks where appropriate), |
| 127 | + - Configuration behavior in bootstrap.py (e.g., how environment variables/config affect the chain). |
| 128 | +- Ensure tests: |
| 129 | + - Are deterministic, |
| 130 | + - Avoid real external network calls when possible (use mocking or fixtures), |
| 131 | + - Use clear, descriptive test names. |
| 132 | +- Run the test suite (e.g., via uv or the project's recommended test command) and ensure all tests pass. |
| 133 | + |
| 134 | +## Documentation |
| 135 | + |
| 136 | +- **Update README.md** to reflect the new functionality: |
| 137 | + - Add or update sections describing: |
| 138 | + - The purpose and scope of the project. |
| 139 | + - The behavior of the chain and what <new elixir request here> means in practice. |
| 140 | + - How to configure FHIR endpoints and any relevant environment variables. |
| 141 | + - How to run the chain, including command examples. |
| 142 | + - How to run tests. |
| 143 | +- Ensure the README is clear and suitable for: |
| 144 | + - Developers integrating or extending the chain, |
| 145 | + - Clinicians or researchers trying to understand the high-level purpose (if relevant). |
| 146 | + |
| 147 | +## Final quality pass |
| 148 | + |
| 149 | +Perform a **final pass** over the project to ensure: |
| 150 | + |
| 151 | +- **Code quality:** |
| 152 | + - Code is idiomatic, consistent with the reference style, and well-structured. |
| 153 | + - No obvious dead code, unused variables, or leftover debug prints. |
| 154 | + - Type hints are used where appropriate (if consistent with the template). |
| 155 | +- **Functionality:** |
| 156 | + - The chain runs end-to-end for at least one realistic scenario implied by <new elixir request here>. |
| 157 | + - FHIR calls behave as expected (or are mockable in tests). |
| 158 | + - Configuration is documented and works as described. |
| 159 | +- **Project integrity:** |
| 160 | + - All imports resolve. |
| 161 | + - Tests pass. |
| 162 | + - README is up to date. |
| 163 | + - The TODO list accurately reflects what has been completed (you may optionally mark completed tasks). |
| 164 | + |
| 165 | +Your final output should include: |
| 166 | + |
| 167 | +- Updated chain.py and bootstrap.py implementing the requested features, |
| 168 | +- Any new/updated tests, |
| 169 | +- Updated pyproject.toml (if dependencies were added), |
| 170 | +- Updated README.md, |
| 171 | +- A clear, up-to-date TODO list (with remaining future improvements, if any). |
| 172 | + |
| 173 | +Now proceed to implement the above steps carefully and methodically. |
0 commit comments