MCPcopy Index your code
hub / github.com/google/adk-python / _prompt_for_function_call

Function _prompt_for_function_call

src/google/adk/cli/cli.py:139–184  ·  view source on GitHub ↗

Prompts the user for a HITL function call and returns the response.

(
    fc_id: str, fc_name: str, args: dict[str, Any]
)

Source from the content-addressed store, hash-verified

137
138
139def _prompt_for_function_call(
140 fc_id: str, fc_name: str, args: dict[str, Any]
141) -> types.Content:
142 """Prompts the user for a HITL function call and returns the response."""
143 if fc_name == _REQUEST_INPUT:
144 message = args.get('message') or 'Input requested'
145 schema = args.get('response_schema')
146 click.echo(f'[HITL input] {message}')
147 if schema:
148 click.echo(f' Schema: {json.dumps(schema)}')
149 elif fc_name == _REQUEST_CONFIRMATION:
150 tool_confirmation = args.get('toolConfirmation', {})
151 hint = tool_confirmation.get('hint', '')
152 original_fc = args.get('originalFunctionCall', {})
153 original_name = original_fc.get('name', 'unknown')
154 click.echo(f'[HITL confirm] {hint or f"Confirm {original_name}?"}')
155 click.echo(' Type "yes" to confirm, anything else to reject.')
156 else:
157 click.echo(f'[HITL] Waiting for input for {fc_name}({args})')
158
159 user_input = input('[user]: ')
160
161 # Build the FunctionResponse.
162 if fc_name == _REQUEST_CONFIRMATION:
163 confirmed = _is_positive_response(user_input)
164 response = {'confirmed': confirmed}
165 else:
166 # Try to parse as JSON, fall back to wrapping as {"result": value}.
167 try:
168 parsed = json.loads(user_input)
169 response = parsed if isinstance(parsed, dict) else {'result': parsed}
170 except (json.JSONDecodeError, ValueError):
171 response = {'result': user_input}
172
173 return types.Content(
174 role='user',
175 parts=[
176 types.Part(
177 function_response=types.FunctionResponse(
178 id=fc_id,
179 name=fc_name,
180 response=response,
181 )
182 )
183 ],
184 )
185
186
187async def run_interactively(

Callers 1

run_interactivelyFunction · 0.85

Calls 2

_is_positive_responseFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected