Class: Agentic::CLI::AgentCommands
- Inherits:
-
Thor
- Object
- Thor
- Agentic::CLI::AgentCommands
- Defined in:
- lib/agentic/cli.rb
Overview
Agent commands
Instance Method Summary collapse
- #build(id_or_name) ⇒ Object
- #create(name) ⇒ Object
- #delete(id_or_name) ⇒ Object
- #list ⇒ Object
- #show(id_or_name) ⇒ Object
Instance Method Details
#build(id_or_name) ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/agentic/cli.rb', line 340 def build(id_or_name) # Initialize agent assembly system Agentic.initialize_agent_assembly # Build the agent agent = UI.with_spinner("Building agent: #{id_or_name}") do Agentic.agent_store.build_agent(id_or_name) end unless agent puts UI.box( "Error", "Agent '#{UI.colorize(id_or_name, :yellow)}' not found or could not be built.", padding: [1, 2, 1, 2], style: {border: {fg: :red}} ) exit 1 end # Format capabilities list capabilities = agent.capabilities.keys.map { |c| "- #{c}" }.join("\n") capabilities = "None" if capabilities.empty? # Show success message with agent details details = [ "Role: #{UI.colorize(agent.role, :magenta)}", "Purpose: #{agent.purpose}", "Capabilities:\n#{capabilities}" ].join("\n") puts UI.box( "Agent Built Successfully", details, padding: [1, 2, 1, 2], style: {border: {fg: :green}} ) end |
#create(name) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/agentic/cli.rb', line 204 def create(name) # Initialize agent assembly system Agentic.initialize_agent_assembly # Create spinner for agent creation agent = UI.with_spinner("Creating agent: #{name}") do # Create new agent agent = Agentic::Agent.new do |a| a.role = [:role] a.purpose = [:purpose] a.backstory = [:backstory] || "" end # Add capabilities if specified [:capabilities]&.each do |capability_name| agent.add_capability(capability_name) rescue => e Agentic.logger.warn("Failed to add capability: #{capability_name} - #{e.}") end # Store the agent Agentic.agent_store.store(agent, name: name) agent end # Format capabilities list capabilities = agent.capabilities.keys.map { |c| "- #{c}" }.join("\n") capabilities = "None" if capabilities.empty? # Show success message with agent details details = [ "Name: #{UI.colorize(name, :blue)}", "Role: #{UI.colorize(agent.role, :magenta)}", "Purpose: #{agent.purpose}", "Capabilities:\n#{capabilities}" ].join("\n") puts UI.box( "Agent Created", details, padding: [1, 2, 1, 2], style: {border: {fg: :green}} ) end |
#delete(id_or_name) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/agentic/cli.rb', line 313 def delete(id_or_name) # Initialize agent assembly system Agentic.initialize_agent_assembly # Create spinner for agent deletion success = UI.with_spinner("Deleting agent: #{id_or_name}") do Agentic.agent_store.delete(id_or_name) end if success puts UI.box( "Agent Deleted", "Agent #{UI.colorize(id_or_name, :blue)} has been deleted successfully.", padding: [1, 2, 1, 2], style: {border: {fg: :yellow}} ) else puts UI.box( "Error", "Agent #{UI.colorize(id_or_name, :blue)} could not be deleted. Please check the ID or name.", padding: [1, 2, 1, 2], style: {border: {fg: :red}} ) end end |
#list ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/agentic/cli.rb', line 142 def list # Initialize agent assembly system Agentic.initialize_agent_assembly # Get stored agents agents = Agentic.agent_store.all if agents.empty? puts UI.box( "Available Agents", "No agents stored yet.\n\n" \ "You can create a new agent with:\n" \ " #{UI.colorize("agentic agent create NAME --role=ROLE --purpose=PURPOSE", :blue)}", padding: [1, 2, 1, 2], style: {border: {fg: :blue}} ) return end output = "" agents.each do |agent| output += "#{UI.colorize(agent[:name], :blue)} (#{agent[:id]}):\n" output += " Stored: #{agent[:timestamp]}\n" if [:detailed] output += " Role: #{agent[:agent][:role]}\n" if agent[:agent] && agent[:agent][:role] output += " Purpose: #{agent[:agent][:purpose]}\n" if agent[:agent] && agent[:agent][:purpose] if agent[:capabilities] && !agent[:capabilities].empty? output += " Capabilities:\n" agent[:capabilities].each do |capability| output += " - #{capability[:name]} (v#{capability[:version]})\n" end end if agent[:metadata] && !agent[:metadata].empty? output += " Metadata:\n" agent[:metadata].each do |key, value| output += " - #{key}: #{value}\n" unless key.to_s == "requirements" end end else capabilities_count = agent[:capabilities] ? agent[:capabilities].size : 0 output += " Capabilities: #{capabilities_count}\n" end output += "\n" end puts UI.box( "Available Agents", output, padding: [1, 2, 1, 2], style: {border: {fg: :blue}} ) end |
#show(id_or_name) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/agentic/cli.rb', line 251 def show(id_or_name) # Initialize agent assembly system Agentic.initialize_agent_assembly # Find the agent agent_config = nil Agentic.agent_store.all.each do |config| if config[:id] == id_or_name || config[:name] == id_or_name agent_config = config break end end unless agent_config puts UI.box( "Error", "Agent '#{UI.colorize(id_or_name, :yellow)}' not found.", padding: [1, 2, 1, 2], style: {border: {fg: :red}} ) exit 1 end # Format the agent details output = "" output += "ID: #{UI.colorize(agent_config[:id], :blue)}\n" output += "Name: #{UI.colorize(agent_config[:name], :blue)}\n" output += "Stored: #{agent_config[:timestamp]}\n" output += "Version: #{agent_config[:version]}\n\n" if agent_config[:agent] output += "Role: #{agent_config[:agent][:role]}\n" if agent_config[:agent][:role] output += "Purpose: #{agent_config[:agent][:purpose]}\n" if agent_config[:agent][:purpose] output += "Backstory: #{agent_config[:agent][:backstory]}\n" if agent_config[:agent][:backstory] output += "\n" end if agent_config[:capabilities] && !agent_config[:capabilities].empty? output += "Capabilities:\n" agent_config[:capabilities].each do |capability| output += " - #{UI.colorize(capability[:name], :magenta)} (v#{capability[:version]})\n" end output += "\n" end if agent_config[:metadata] && !agent_config[:metadata].empty? output += "Metadata:\n" agent_config[:metadata].each do |key, value| next if key.to_s == "requirements" # Skip complex requirements object output += " - #{key}: #{value}\n" end end puts UI.box( "Agent Details", output, padding: [1, 2, 1, 2], style: {border: {fg: :blue}} ) end |