@prefix convo: <https://ontology.inferal.com/modules/conversation/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix prof: <http://www.w3.org/ns/dx/prof/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix role: <http://www.w3.org/ns/dx/prof/role/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

convo:AgentExecutionProfile
    a prof:Profile ;
    prof:isProfileOf convo: ;
    prof:hasResource <https://ontology.inferal.com/modules/conversation/profiles/agent-execution#constraints> .

<https://ontology.inferal.com/modules/conversation/profiles/agent-execution#constraints>
    a prof:ResourceDescriptor ;
    rdfs:label "Agent Execution constraints descriptor"@en ;
    rdfs:comment "Describes the SHACL artifact that validates model and tool contribution-production workflows."@en ;
    prof:hasArtifact <https://ontology.inferal.com/modules/conversation/profiles/agent-execution.ttl> ;
    prof:hasRole role:constraints, role:validation ;
    dcterms:conformsTo <http://www.w3.org/ns/shacl#> ;
    dcterms:format <https://www.iana.org/assignments/media-types/text/turtle> .

convo:ModelInvocationShape
    a sh:NodeShape ;
    rdfs:label "model invocation shape"@en ;
    rdfs:comment "Requires a model invocation to identify one model, a responsible software agent, and at least one generated contribution."@en ;
    sh:targetClass convo:ModelInvocation ;
    sh:property [ sh:path convo:usedModel ; sh:class convo:Model ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path prov:wasAssociatedWith ; sh:class prov:SoftwareAgent ; sh:minCount 1 ] ;
    sh:property [ sh:path prov:generated ; sh:class convo:Contribution ; sh:minCount 1 ] .

convo:ToolInvocationShape
    a sh:NodeShape ;
    rdfs:label "tool invocation shape"@en ;
    rdfs:comment "Requires a tool invocation to identify one tool, its request, and at least one generated tool result."@en ;
    sh:targetClass convo:ToolInvocation ;
    sh:property [ sh:path convo:invokedTool ; sh:class convo:Tool ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path convo:requestedBy ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:property [ sh:path prov:generated ; sh:class convo:ToolResult ; sh:minCount 1 ] .

convo:ToolResultExecutionShape
    a sh:NodeShape ;
    rdfs:label "tool result execution shape"@en ;
    rdfs:comment "Requires each tool-result contribution in Agent Execution data to identify exactly one generating tool invocation with a reciprocal output relation."@en ;
    sh:targetClass convo:ToolResult ;
    sh:property [ sh:path prov:wasGeneratedBy ; sh:class convo:ToolInvocation ; sh:minCount 1 ; sh:maxCount 1 ] ;
    sh:sparql [
        sh:message "The tool invocation named by a ToolResult must point back with prov:generated."@en ;
        sh:select """
            PREFIX prov: <http://www.w3.org/ns/prov#>
            SELECT $this ?activity WHERE {
                $this prov:wasGeneratedBy ?activity .
                FILTER NOT EXISTS { ?activity prov:generated $this . }
            }
        """ ;
    ] .

convo:AgentContributionShape
    a sh:NodeShape ;
    rdfs:label "agent contribution shape"@en ;
    rdfs:comment "Requires contributions in agent-execution data to state their conversational role."@en ;
    sh:targetClass convo:Contribution ;
    sh:property [ sh:path convo:hasContributionRole ; sh:class convo:ContributionRole ; sh:minCount 1 ; sh:maxCount 1 ] .
