Class: Agentic::TaskOutputSchemas

Inherits:
Object
  • Object
show all
Defined in:
lib/agentic/task_output_schemas.rb

Overview

Registry for managing task output schemas Provides a centralized location for defining and accessing structured output schemas used by tasks

Class Method Summary collapse

Class Method Details

.analysis_schemaAgentic::StructuredOutputs::Schema

Returns a schema for analysis/research tasks

Returns:



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/agentic/task_output_schemas.rb', line 79

def analysis_schema
  @analysis_schema ||= StructuredOutputs::Schema.new("analysis_result") do |schema|
    schema.string(:summary)
    schema.array(:key_findings, items: {type: "string"})
    schema.object(:data) do
      # Flexible analysis data
    end
    schema.array(:recommendations, items: {type: "string"})
    schema.string(:confidence_level, enum: ["high", "medium", "low"])
  end
end

.code_generation_schemaAgentic::StructuredOutputs::Schema

Returns a schema for code generation tasks

Returns:



67
68
69
70
71
72
73
74
75
# File 'lib/agentic/task_output_schemas.rb', line 67

def code_generation_schema
  @code_generation_schema ||= StructuredOutputs::Schema.new("code_generation") do |schema|
    schema.string(:language)
    schema.string(:filename)
    schema.string(:code)
    schema.string(:description)
    schema.array(:dependencies, items: {type: "string"})
  end
end

.default_task_schemaAgentic::StructuredOutputs::Schema

Returns the default task output schema for general task responses

Returns:



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/agentic/task_output_schemas.rb', line 40

def default_task_schema
  @default_schema ||= StructuredOutputs::Schema.new("task_output") do |schema|
    # Simple, flexible schema for task results
    schema.string(:status, enum: ["completed", "partial", "failed"])
    schema.object(:result) do |result_schema|
      result_schema.string(:summary)
      # Additional properties will be allowed for flexible task outputs
    end
    schema.array(:steps, items: {type: "string"})
  end
end

.exists?(name) ⇒ Boolean

Checks if a schema is registered

Parameters:

  • name (Symbol)

    The schema name/identifier

Returns:

  • (Boolean)

    True if schema exists



34
35
36
# File 'lib/agentic/task_output_schemas.rb', line 34

def exists?(name)
  @schemas.key?(name) || name == :default
end

.get(name) ⇒ Agentic::StructuredOutputs::Schema?

Retrieves a registered schema

Parameters:

  • name (Symbol)

    The schema name/identifier

Returns:



21
22
23
# File 'lib/agentic/task_output_schemas.rb', line 21

def get(name)
  @schemas[name] || ((name == :default) ? default_task_schema : nil)
end

.list_schemasArray<Symbol>

Lists all registered schema names

Returns:

  • (Array<Symbol>)

    Array of schema names



27
28
29
# File 'lib/agentic/task_output_schemas.rb', line 27

def list_schemas
  (@schemas.keys + [:default]).uniq
end

.register(name, schema) ⇒ Object

Registers a new output schema

Parameters:



14
15
16
# File 'lib/agentic/task_output_schemas.rb', line 14

def register(name, schema)
  @schemas[name] = schema
end

.register_defaults!Object

Registers default schemas



101
102
103
104
105
106
# File 'lib/agentic/task_output_schemas.rb', line 101

def register_defaults!
  register(:default, default_task_schema)
  register(:simple_object, simple_object_schema)
  register(:code_generation, code_generation_schema)
  register(:analysis, analysis_schema)
end

.reset!Object

Resets all registered schemas (useful for testing)



92
93
94
95
96
97
98
# File 'lib/agentic/task_output_schemas.rb', line 92

def reset!
  @schemas = {}
  @default_schema = nil
  @simple_object_schema = nil
  @code_generation_schema = nil
  @analysis_schema = nil
end

.simple_object_schemaAgentic::StructuredOutputs::Schema

Returns a simple object schema for maximum flexibility

Returns:



54
55
56
57
58
59
60
61
62
63
# File 'lib/agentic/task_output_schemas.rb', line 54

def simple_object_schema
  @simple_object_schema ||= StructuredOutputs::Schema.new("simple_object") do |schema|
    # Minimal schema that accepts any structured JSON object
    # This is useful when we want structured JSON but maximum flexibility
    schema.string(:type)
    schema.object(:data) do
      # Flexible data structure
    end
  end
end