ontocast.agent.common¶
call_llm_with_retry(llm_tool, prompt, parser, prompt_kwargs, max_retries=3, retry_error_feedback=True)
async
¶
Call LLM and parse response with automatic retry on parsing failures.
This utility function implements a common pattern across agent functions: 1. Call LLM with a prompt 2. Parse the response 3. Retry if parsing fails (up to max_retries times)
On retry, if retry_error_feedback is True, the error message from the previous attempt is included in the prompt to help the LLM correct its output format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm_tool
|
LLMTool
|
The LLM tool instance to use for generation. |
required |
prompt
|
BasePromptTemplate
|
The prompt template to format and send to the LLM. |
required |
parser
|
BaseOutputParser[T]
|
The output parser to parse the LLM response. |
required |
prompt_kwargs
|
dict[str, Any]
|
Keyword arguments to pass to prompt.format_prompt(). |
required |
max_retries
|
int
|
Maximum number of retry attempts (default: 3). |
3
|
retry_error_feedback
|
bool
|
Whether to include error feedback in retry prompts (default: True). |
True
|
Returns:
| Type | Description |
|---|---|
T
|
The parsed output of type T. |
Raises:
| Type | Description |
|---|---|
Exception
|
If parsing fails after all retry attempts, raises the last parsing error. |
Source code in ontocast/agent/common.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
render_suggestions_prompt(suggestions, stage)
¶
Generate prompt templates from the suggestions.
Returns:
| Type | Description |
|---|---|
str
|
Combined string with general and concrete templates. |
str
|
Returns empty string if both fields are empty. |