Merge pull request #98 from Praveenk8051/feat/add-documentation-for-module-extensions

Add Module class documentation and interface example
This commit is contained in:
Alexander Myasoedov
2025-01-25 12:29:32 +02:00
committed by GitHub
2 changed files with 49 additions and 0 deletions
+4
View File
@@ -376,6 +376,10 @@ This sample GitHub Action is designed to perform automated security scans
This setup ensures a continuous integration approach towards maintaining security in your projects.
## Module Class
The `Module` class is designed to manage prompt processing and interaction with external AI models and tools. It supports fetching, processing, and posting prompts asynchronously for model vulnerabilities. Check out [module.md](https://github.com/msoedov/agentic_security/blob/main/docs/module.md) for details.
## Documentation
For more detailed information on how to use Agentic Security, including advanced features and customization options, please refer to the official documentation.
+45
View File
@@ -0,0 +1,45 @@
## Module Interface Documentation
The `Module` class interface provides a standardized way to create and use modules in the `agentic_security` project.
Here is an example of a module that implements the `ModuleProtocol` interface. This example shows how to create a module that processes prompts and sends results to a queue.
```python
from typing import List, Dict, Any, AsyncGenerator
import asyncio
from .module_protocol import ModuleProtocol
class ModuleProtocol(ModuleProtocol):
def __init__(self, prompt_groups: List[Any], tools_inbox: asyncio.Queue, opts: Dict[str, Any]):
self.prompt_groups = prompt_groups
self.tools_inbox = tools_inbox
self.opts = opts
async def apply(self) -> AsyncGenerator[str, None]:
for group in self.prompt_groups:
await asyncio.sleep(1)
result = f"Processed {group}"
await self.tools_inbox.put(result)
yield result
```
#### Usage Example
```python
import asyncio
import ModuleProtocol
tools_inbox = asyncio.Queue()
prompt_groups = ["group1", "group2"]
opts = {"max_prompts": 1000, "batch_size": 100}
module = ModuleProtocol(prompt_groups, tools_inbox, opts)
async def main():
async for result in module.apply():
print(result)
asyncio.run(main())
```