mirror of https://github.com/aliasrobotics/cai.git
Robut ctf param
This commit is contained in:
parent
16e8489556
commit
3d3be8c7df
|
|
@ -703,19 +703,6 @@ def run_cai_cli(starting_agent, context_variables=None, max_turns=float('inf')):
|
|||
|
||||
except KeyboardInterrupt:
|
||||
print("\n\033[91mKeyboard interrupt detected\033[0m")
|
||||
|
||||
if hasattr(agent, 'model'):
|
||||
from cai.sdk.agents.models.openai_chatcompletions import _Converter
|
||||
if hasattr(_Converter, 'recent_tool_calls'):
|
||||
for call_id, call_info in _Converter.recent_tool_calls.items():
|
||||
# Add a tool response indicating the interruption
|
||||
tool_msg = {
|
||||
"role": "tool",
|
||||
"tool_call_id": call_id,
|
||||
"content": "Operation interrupted by user",
|
||||
}
|
||||
add_to_message_history(tool_msg)
|
||||
|
||||
pass
|
||||
except Exception as e:
|
||||
import traceback
|
||||
|
|
|
|||
|
|
@ -343,7 +343,7 @@ class OpenAIChatCompletionsModel(Model):
|
|||
from cai.util import fix_message_list
|
||||
converted_messages = fix_message_list(converted_messages)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to fix message list: {e}")
|
||||
pass
|
||||
|
||||
# Get token count estimate before API call for consistent counting
|
||||
estimated_input_tokens, _ = count_tokens_with_tiktoken(converted_messages)
|
||||
|
|
@ -1463,7 +1463,7 @@ class OpenAIChatCompletionsModel(Model):
|
|||
if new_length != prev_length:
|
||||
logger.debug(f"Message list was fixed: {prev_length} -> {new_length} messages")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to fix message list: {e}")
|
||||
pass
|
||||
|
||||
parallel_tool_calls = (
|
||||
True if model_settings.parallel_tool_calls and tools and len(tools) > 0 else NOT_GIVEN
|
||||
|
|
@ -1702,7 +1702,7 @@ class OpenAIChatCompletionsModel(Model):
|
|||
|
||||
kwargs["messages"] = fixed_messages
|
||||
except Exception as fix_error:
|
||||
print(f"Failed to fix message sequence: {fix_error}")
|
||||
pass
|
||||
|
||||
return await self._fetch_response_litellm_openai(kwargs, model_settings, tool_choice, stream, parallel_tool_calls)
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ class ShellSession: # pylint: disable=too-many-instance-attributes
|
|||
except Exception as e:
|
||||
self.output_buffer.append(f"Error starting container session: {str(e)}")
|
||||
self.is_running = False
|
||||
return
|
||||
return str(e)
|
||||
|
||||
# --- Start in CTF ---
|
||||
if self.ctf:
|
||||
|
|
@ -141,8 +141,8 @@ class ShellSession: # pylint: disable=too-many-instance-attributes
|
|||
self.output_buffer.append(output)
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
self.output_buffer.append(f"Error executing CTF command: {str(e)}")
|
||||
self.is_running = False
|
||||
return
|
||||
self.is_running = False
|
||||
return str(e)
|
||||
|
||||
# --- Start Locally (Host) ---
|
||||
try:
|
||||
|
|
@ -167,7 +167,7 @@ class ShellSession: # pylint: disable=too-many-instance-attributes
|
|||
except Exception as e: # pylint: disable=broad-except
|
||||
self.output_buffer.append(f"Error starting local session: {str(e)}")
|
||||
self.is_running = False
|
||||
|
||||
return str(e)
|
||||
def _read_output(self):
|
||||
"""Read output from the process"""
|
||||
try:
|
||||
|
|
@ -195,6 +195,7 @@ class ShellSession: # pylint: disable=too-many-instance-attributes
|
|||
except Exception as e:
|
||||
self.output_buffer.append(f"Error in read_output loop: {str(e)}")
|
||||
self.is_running = False
|
||||
return str(e)
|
||||
|
||||
|
||||
def is_process_running(self):
|
||||
|
|
@ -645,6 +646,8 @@ def _run_local(command, stdout=False, timeout=100, stream=False, call_id=None, t
|
|||
|
||||
if stdout:
|
||||
print("\033[32m" + error_msg + "\033[0m")
|
||||
return error_msg
|
||||
|
||||
|
||||
return error_msg
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
|
|
@ -1258,15 +1261,10 @@ def run_command(command, ctf=None, stdout=False, # pylint: disable=too-many-arg
|
|||
custom_args=args
|
||||
)
|
||||
|
||||
# Switch back to idle mode after local command completes
|
||||
stop_active_timer()
|
||||
start_idle_timer()
|
||||
return result
|
||||
except Exception as KeyboardInterrupt:
|
||||
stop_active_timer()
|
||||
start_idle_timer()
|
||||
return "User interrupted execution pressing ctrl+c"
|
||||
except Exception as e:
|
||||
stop_active_timer()
|
||||
start_idle_timer()
|
||||
return f"Error: {str(e)}"
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -844,7 +844,6 @@ def fix_message_list(messages): # pylint: disable=R0914,R0915,R0912
|
|||
i += 2
|
||||
else:
|
||||
i += 1
|
||||
|
||||
return sanitized_messages
|
||||
|
||||
def cli_print_tool_call(tool_name="", args="", output="", prefix=" "):
|
||||
|
|
@ -2103,8 +2102,8 @@ def print_message_history(messages, title="Message History"):
|
|||
table = Table(show_header=True, header_style="bold magenta", expand=True)
|
||||
table.add_column("#", style="dim", width=3)
|
||||
table.add_column("Role", style="cyan", width=10)
|
||||
table.add_column("Content", width=40)
|
||||
table.add_column("Metadata", width=30)
|
||||
table.add_column("Content", width=1000)
|
||||
table.add_column("Metadata", width=1000)
|
||||
|
||||
# Process each message
|
||||
for i, msg in enumerate(messages):
|
||||
|
|
|
|||
Loading…
Reference in New Issue